Search code examples
exceljuliaxlsx

Reading all Excel cells as text in Julia using XLSX package


I'm working with the Julia programming language and using the XLSX package to read an Excel file. However, I'm encountering an issue where some cells in the Excel file are being read as numbers when I need them to be read as text. The Excel file has both numbers and Strings randomly.

Here's the code I'm using to read the Excel file:

import XLSX
xf = XLSX.readxlsx("myfile.xlsx")

I was expecting all cells in the Excel file to be read as text, including numerical values. I want to ensure that no data is automatically treated as numbers.


Solution

  • I converted the Matrix{Any} type to Matrix{AbstractString} as follows:

    #Read Excel file into cells(Matrix{Any}[280,3]) variable
    cells = XLSX.readdata("/home/***/ExcelFile.xlsx", "Sheet", "A1:C280")
    
    #Convert cells from Matrix{Any} to Matrix{AbstractString}
    for i in 1:size(cells,1)
        for j in 1:size(cells,2)
        cells[i,j] = string(cells[i,j])
        end
    end
    cells = convert(Matrix{AbstractString}, cells)