Byte array into Excel using C#.
-
I am having a webservice which creates an excel file in server and sends back it as byte array. Now i want to write that byte arry in excel file in the client side.can any body help me out.It's an winform application.
kurangu wrote:
i want to write that byte arry in excel file in the client side.
Well if those bytes represent the bytes of the Excel file then you just write them to a file. If they are something else then we don't know what they are so we can't help you.
led mike
-
kurangu wrote:
i want to write that byte arry in excel file in the client side.
Well if those bytes represent the bytes of the Excel file then you just write them to a file. If they are something else then we don't know what they are so we can't help you.
led mike
-
Mike, It's an bytes of excel file.But when I write in client side.Not able to open the excel file.It says not in recognizable format is there any format getting changed by webservice.
-
kurangu wrote:
is there any format getting changed by webservice.
how could I possibly know what the webservice is doing? :confused:
led mike
string sfilename = @"C:\\\\test.xls"; FileStream fs = new FileStream(sfilename, FileMode.Create); xlw.Save(wb, fs); byte[] binFile = new byte[fs.Length]; fs.Read(binFile, 0, (int)fs.Length); fs.Close(); return binfile. Mike the above code returns the byte(right now I am saving the excel file with test.xls in server) after that i am getting the byte. client coe:- ----- byte[]test=webservice.getdata(); FileStream output = new FileStream("C:\\test2.xls", FileMode.Create,FileAccess.Write); output.Write(test, 0, test.Length); output.Close(); Test 2 created with the same size as test in server but when i open I am geeting format not good.with empty xls.
-
string sfilename = @"C:\\\\test.xls"; FileStream fs = new FileStream(sfilename, FileMode.Create); xlw.Save(wb, fs); byte[] binFile = new byte[fs.Length]; fs.Read(binFile, 0, (int)fs.Length); fs.Close(); return binfile. Mike the above code returns the byte(right now I am saving the excel file with test.xls in server) after that i am getting the byte. client coe:- ----- byte[]test=webservice.getdata(); FileStream output = new FileStream("C:\\test2.xls", FileMode.Create,FileAccess.Write); output.Write(test, 0, test.Length); output.Close(); Test 2 created with the same size as test in server but when i open I am geeting format not good.with empty xls.
Can you open the spreadsheet thats saved on the server before its transmitted to the client? Something smells fishy about your file saving code. You create the FileStream with FileMode.Create Then you try to use that file stream to read. I don't think thats the correct way of reading/writing files.
Just because we can; does not mean we should.
-
string sfilename = @"C:\\\\test.xls"; FileStream fs = new FileStream(sfilename, FileMode.Create); xlw.Save(wb, fs); byte[] binFile = new byte[fs.Length]; fs.Read(binFile, 0, (int)fs.Length); fs.Close(); return binfile. Mike the above code returns the byte(right now I am saving the excel file with test.xls in server) after that i am getting the byte. client coe:- ----- byte[]test=webservice.getdata(); FileStream output = new FileStream("C:\\test2.xls", FileMode.Create,FileAccess.Write); output.Write(test, 0, test.Length); output.Close(); Test 2 created with the same size as test in server but when i open I am geeting format not good.with empty xls.
Open up both files in xvi32 (or another hex editor) and see if there are any obvious differences, like all the bytes are 00 for example. The most probably place for an error is right at the beggining and right at the end, so check there first.
My current favourite word is: Nipple!
-SK Genius
-
Can you open the spreadsheet thats saved on the server before its transmitted to the client? Something smells fishy about your file saving code. You create the FileStream with FileMode.Create Then you try to use that file stream to read. I don't think thats the correct way of reading/writing files.
Just because we can; does not mean we should.
I think they create a new file, then
xls.Save(wb, fs);
writes the actual spreadsheet to the file. After which they read the data back, which shouldn't be a problem i beleive...My current favourite word is: Bacon!
-SK Genius