|
Hi,
I have an asp.net WCF Service, my client application is going to send me excel file as byte array. I have to read those bytes and upload data in the database.
Microsoft Jet, or Ace drivers take the excel file name, is there any way that I can read those excel file bytes directly without storing the file in my file system.
Thanks in advance.
Thanks & Regards,
Abdul Aleem Mohammad
St Louis MO - USA
|
|
|
|
|
you make a byte() array for the source, and then copy it to a memorysteam if needed, or just pass the byte array to the destination.
Something like this, I don't something to test it on now
Dim excelFile As byte() = {input}
ByVal excelFile() As Byte
If you need a primitive, that's different.
credit to
[vinz^]
Dim arr As New ArrayList()
arr.Add("AAA")
arr.Add("BBB")
arr.Add("CCC")
Dim byteArray As Byte() = New Byte(2) {}
For i As Integer = 0 To arr.Count - 1
byteArray = DirectCast(arr(i), Byte())
Next
'Read byteArray to stream
Dim stream As New System.IO.MemoryStream(byteArray)
|
|
|
|
|
Hi,
Here I am at the destination side, so I receive excel in byte array format. Then I want to read that array similar to the way we read from excel file using jet or ace drivers.
Is there any way that I can read from a byte array (the byte array created by excel file and I should be able to read the data as if I am reading from an excel file (like row wise and column wise)), actually I am reading from byte array or memorystream created by byte array.
I am able to create memory stream from byte array, but I am unable to read as if I am reading from excel. One more important thing, I dont want to save my file on to the file system, if I save on to file system, I am able to read using oledb jet or ace drivers, but I dont want to save on to the file system.
Is there any way to do that?
I have to update in the database that part I will take care.
Thanks & Regards,
Abdul Aleem Mohammad
St Louis MO - USA
modified 10-Aug-12 19:48pm.
|
|
|
|
|
I thought you just wanted to store the file. Yes You can do that, but i don't how.
Guess you cross that road when you get to it. if your able to store the byte array.
With all do respect, meaning something else
I find it hard to believe that your selling services that you have no clue how to do.
I don't mind helping you, but eventually you need to give something back to CJ, like answer some questions for other OPs, and not be a pure consumer
This reads the dimensions of a flash file from a pure byte stream, just an in insight into what you wish to achieve. I have no interest in reading a excel file, so I'm stopping here at this point. When you ready to ready bytes and translate them into bits, let me know.
Private Function getDimensions(ByVal stream As Stream) As Rectangle
Dim inputStream As Stream = Nothing
Dim signature() As Byte = New Byte(8) {}
Dim rect() As Byte = New Byte(8) {}
stream.Read(signature, 0, 8)
If (System.Text.Encoding.ASCII.GetString(signature, 0, 3) = "CWS") Then
inputStream = New InflaterInputStream(stream)
Else
inputStream = stream
End If
inputStream.Read(rect, 0, 8)
Dim nbits As Integer = rect(0) >> 3
rect(0) = Convert.ToByte(rect(0) And &H7)
Dim bits As String = ByteArrayToBitString(rect)
bits = bits.Remove(0, 5)
Dim dims() As Integer = New Integer(4) {}
For i As Integer = 0 To 3
Dim dest() As Char = New Char(nbits) {}
bits.CopyTo(0, dest, 0, If(bits.Length > nbits, nbits, bits.Length))
bits = bits.Remove(0, If(bits.Length > nbits, nbits, bits.Length))
dims(i) = BitStringToInteger(New String(dest)) / 20
Next
Return New Rectangle(0, 0, dims(1) - dims(0), dims(3) - dims(2))
End Function
Private Function BitStringToInteger(ByVal bits As String) As Integer
Dim converted As Integer = 0
For i As Integer = 0 To bits.Length - 2
converted = (converted << 1) + If(bits(i) = "1", 1, 0)
Next
Return converted
End Function
Private Function ByteArrayToBitString(ByVal byteArray() As Byte) As String
Dim newByteArray() As Byte = New Byte(byteArray.Length) {}
Array.Copy(byteArray, newByteArray, byteArray.Length)
Dim converted As String = ""
For i As Integer = 0 To newByteArray.Length - 1
For j As Integer = 0 To 7
converted += If((newByteArray(i) And &H80) > 0, "1", "0")
newByteArray(i) <<= 1
Next
Next
Return converted
End Function
|
|
|
|