Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Byte array into Excel using C#.

Byte array into Excel using C#.

Scheduled Pinned Locked Moved C#
csharpsysadmindata-structureshelp
8 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kurangu
    wrote on last edited by
    #1

    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.

    L 1 Reply Last reply
    0
    • K kurangu

      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.

      L Offline
      L Offline
      led mike
      wrote on last edited by
      #2

      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

      K 1 Reply Last reply
      0
      • L 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

        K Offline
        K Offline
        kurangu
        wrote on last edited by
        #3

        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.

        L 1 Reply Last reply
        0
        • K kurangu

          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.

          L Offline
          L Offline
          led mike
          wrote on last edited by
          #4

          kurangu wrote:

          is there any format getting changed by webservice.

          how could I possibly know what the webservice is doing? :confused:

          led mike

          K 1 Reply Last reply
          0
          • L led mike

            kurangu wrote:

            is there any format getting changed by webservice.

            how could I possibly know what the webservice is doing? :confused:

            led mike

            K Offline
            K Offline
            kurangu
            wrote on last edited by
            #5

            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.

            K A 2 Replies Last reply
            0
            • K kurangu

              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.

              K Offline
              K Offline
              KaptinKrunch
              wrote on last edited by
              #6

              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.

              A 1 Reply Last reply
              0
              • K kurangu

                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.

                A Offline
                A Offline
                Anthony Mushrow
                wrote on last edited by
                #7

                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

                1 Reply Last reply
                0
                • K KaptinKrunch

                  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.

                  A Offline
                  A Offline
                  Anthony Mushrow
                  wrote on last edited by
                  #8

                  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

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups