I am looking for a package which can read and write an excel file cell by cell. I know openpyxl do the job. Is there any other better package in Julia which does the same job?
Now, I am trying to install it, so I used the following piece of code:
using Pkg
import Conda
Conda.add("openpyxl")
ENV["PYTHON"]="C:\\Python37-x64\\python.exe"; Pkg.build("PyCall")
@pyimport openpyxl
I am getting the following error:
LoadError: LoadError: UndefVarError: @pyimport not defined
in expression starting at C:\Users\Administrator\Desktop\Test Code [Julia]\TESTING_1.jl:14
in expression starting at C:\Users\Administrator\Desktop\Test Code [Julia]\TESTING_1.jl:14
top-level scope
Another point: If you want to use Conda.jl to install openpyxl, donât do ENV["PYTHON"]="C:\\Python37-x64\\python.exe"; Pkg.build("PyCall"). Run ENV["PYTHON"]=""; Pkg.build("PyCall").
Thanks for your response. I have changed the code as follows:
import Conda
import Pkg
Conda.add("openpyxl")
ENV["PYTHON"]=""; Pkg.build("PyCall")
using PyCall
pyimport("openpyxl")
Still, I am getting the following error:
LoadError: ArgumentError: Package PyCall not found in current path:
-Run import Pkg; Pkg.add("PyCall") to install the PyCall package.
in expression starting at C:\Users\Administrator\Desktop\Rajat_Sanyal\Test Code [Julia]\TESTING_1.jl:14
require(::Module, ::Symbol) at loading.jl:823
I have found two Julia folders in my system (added both of them in the environment variables) which are as follows:
I have used the XLSX.jl package for data writing, but have not tried for reading. Actually, I have seen the tutorial, but only few examples are provided. I was not sure how it could be used to read an excel file cell by cell. I will try once again, and let you know about it. Thanks!
Hi, @YongHee-Kim thanks for your input. Let me put my problem properly.
Let us consider we have an excel sheet which contains cities in a row and population is a column. Now, we donât know how many cities are there. I am trying to write a program which will take the number of cities as an input from a user/or a cell, then save the data in an array.
Let me try to write a mock code:
G = 10; # Input
v = zeros(1,10)
f = XLSX.openxlsx("DATA.xlsx", enable_cache=false)
sheet = f["Sheet1"]
for g in 1:G
v = sheet[g+1,2]
println("v=$v")
end
You can access all of your excel data with just numbers
you donât need excel address types
using XLSX
xf = XLSX.readxlsx("data.xlsx")
# All datas in 'Sheet1'
mydata = xf["Sheet1"][:]
# access to range
firstrow = mydata[1, :]
firstcolumn = mydata[:, 1]
# so if you want datas until 10th row
g = 10
columnA = mydata[1:g, 1]
columnB = mydata[1:g, 2]
In this case, it reads the whole file first which may be a cumbersome job. Is it possible to extract the data directly? Go to the sheet and extract the columns/rows using the numbers (not using the excel address).
I guess that will drastically reduce the reading time.