Main Site Documentation

How can I read the something in Excel file from a fixed position to anthor fixed position


#1

I use EMX, I have a excel file (see picture 1) and the excel file is saved in the USB Stick.

I define 4 double/bool array as follow:


        public static bool[] P_RW = new bool[1000];
        public static double[] P_Min = new double[1000];
        public static double[] P_Max = new double[1000];
        public static double[] P_Voreinstellung= new double[1000];

How can I read the content of “column C(D,E,F)” one for one to array P_RW(P_Min,P_Max,P_Voreinstellung)?

I mean I want to initialize the 4 arrays with a excel file in the USB Stick.


#2

That depends on the library you are using to open and read that file format. What do you use for that?


#3

@ Architect -

I have written somecodes for writing and reading some simple text into/from a file

something like as follow:


StreamWriter textFile = new StreamWriter(Parameter.USBCardRootDirectory + @ "\hello.txt");
textFile.WriteLine("Hello USB card");

or


FileStream fHandle = new FileStream(path, FileMode.Open, FileAccess.Read);
 byte[] data = new byte[fHandle.Length];
fHandle.Read(data, 0, data.Length);
fHandle.Close();

I have used the library “System.IO.StreamWriter” and “System.IO.FileStream”

Does the library have the function for serching a position in a excel file and read the content of Square one by one and save them one by one to a array?


#4

It would be easier to save the file as CSV file and read it line by line.


#5

I agree with Architect.
The newer versions of excel files are really a “zip” file with several xml files embedded. One could extract the xml file that contains the data and then parse that.


#6

Also agree. Don’t try messing with the Excel native files. Too much work.


#7

In a project on big .Net we are using Koogra as an api for excell file. As far as I know there’s no such library on .netmf.


#8

Thank you all of you°!
CSV file works well in my project !


#9

Yep, making it simple at the input solves a lot of issues. Glad you got it working.


#10

the ‘right’ way to to start Excel as an OLE server and ask it to open the file :slight_smile:

but since youre not on Windows, the CSV is a lot betterer


#11

@ Architect -

Yep, making it simple at the input solves a lot of issues. …

That is the wav my old brain likes it too…