marcick Well-Known Member Licensed User Longtime User Jan 9, 2023 #1 Hi all, I need my App be able to generate an Excel files. I do it in B4A but I know there is not the Excel library in B4i. Because my app communicate with my server where a B4J server application is running, I was thinking to send a text file or a db to the server, that make the conversion in B4J and send back the Excel file. Which is the best way to excange files (let's say small files less than 500KB) from B4A and the server ? Thanks
Hi all, I need my App be able to generate an Excel files. I do it in B4A but I know there is not the Excel library in B4i. Because my app communicate with my server where a B4J server application is running, I was thinking to send a text file or a db to the server, that make the conversion in B4J and send back the Excel file. Which is the best way to excange files (let's say small files less than 500KB) from B4A and the server ? Thanks
E emexes Expert Licensed User Longtime User Jan 9, 2023 #2 What happens with your generated Excel files? How are they handled/used after they leave your app? Does the process already exist, eg are Excel files like those that your app needs to generate, already being created by an existing program, or manually (presumably in Excel) ? Upvote 0
What happens with your generated Excel files? How are they handled/used after they leave your app? Does the process already exist, eg are Excel files like those that your app needs to generate, already being created by an existing program, or manually (presumably in Excel) ?
marcick Well-Known Member Licensed User Longtime User Jan 9, 2023 #3 Once the Excel file is generated, the use can open it with office mobile or eventually share and send it to an email address etc. But this is not really relevant. Which is the best way to excange files from B4A and the B4J server ? Upvote 0
Once the Excel file is generated, the use can open it with office mobile or eventually share and send it to an email address etc. But this is not really relevant. Which is the best way to excange files from B4A and the B4J server ?
E emexes Expert Licensed User Longtime User Jan 9, 2023 #4 marcick said: But this is not really relevant. Click to expand... I would say it is super-relevant. If your app can directly produce a file that serves whatever purpose the Excel file is being used for, then you'd no longer need to run a server and transfer files back and forth. Less complexity, less cost, less to go wrong, fewer links to break. But I am getting the vibe that there are other considerations at play here too, so... no worries, I'll not push that barrow any further. ? My first go-to for transferring files between computers with non-permanent IP addresses or domain names, is to use FTP, especially if your company already has an FTP server operating somewhere. Bonus is that you (can) have a log/archive/backup of the data transferred, if the intermediate files have unique names eg based on date-time-user. Downside is that the latency/turnaround-time might drive your users nuts. Upvote 0
marcick said: But this is not really relevant. Click to expand... I would say it is super-relevant. If your app can directly produce a file that serves whatever purpose the Excel file is being used for, then you'd no longer need to run a server and transfer files back and forth. Less complexity, less cost, less to go wrong, fewer links to break. But I am getting the vibe that there are other considerations at play here too, so... no worries, I'll not push that barrow any further. ? My first go-to for transferring files between computers with non-permanent IP addresses or domain names, is to use FTP, especially if your company already has an FTP server operating somewhere. Bonus is that you (can) have a log/archive/backup of the data transferred, if the intermediate files have unique names eg based on date-time-user. Downside is that the latency/turnaround-time might drive your users nuts.
marcick Well-Known Member Licensed User Longtime User Jan 9, 2023 #5 emexes said: If your app can directly produce a file that serves whatever purpose the Excel file is being used for ...... Click to expand... No, my app can't. My B4A app can, but B4i app not, because there is no Excel library for B4i. There is a workaround that I'm using but I want to move to another solution. And I need a standard Excel file. I don't want to install the FTP service on my WAMP server, I had trouble in the past. Because files are small size, I would prefer some other method (HTTP request ? Websocket ?) Upvote 0
emexes said: If your app can directly produce a file that serves whatever purpose the Excel file is being used for ...... Click to expand... No, my app can't. My B4A app can, but B4i app not, because there is no Excel library for B4i. There is a workaround that I'm using but I want to move to another solution. And I need a standard Excel file. I don't want to install the FTP service on my WAMP server, I had trouble in the past. Because files are small size, I would prefer some other method (HTTP request ? Websocket ?)
Erel B4X founder Staff member Licensed User Longtime User Jan 10, 2023 #6 Simply send a post request with the file contents and read it on the server with: Code: Copy Dim b() As Byte = Bit.InputStreamToBytes(req.InputStream) Upvote 0
Simply send a post request with the file contents and read it on the server with: Code: Copy Dim b() As Byte = Bit.InputStreamToBytes(req.InputStream)
marcick Well-Known Member Licensed User Longtime User Jan 10, 2023 #7 Erel said: Simply send a post request with the file contents and read it on the server with: Code: Copy Dim b() As Byte = Bit.InputStreamToBytes(req.InputStream) Click to expand... Thank you !. I found the full Tutorial to send files. Now, if the file is a text file and I just need to scan all the lines, how do I manage the b() array ? Sorry if the question looks stupid .... Upvote 0
Erel said: Simply send a post request with the file contents and read it on the server with: Code: Copy Dim b() As Byte = Bit.InputStreamToBytes(req.InputStream) Click to expand... Thank you !. I found the full Tutorial to send files. Now, if the file is a text file and I just need to scan all the lines, how do I manage the b() array ? Sorry if the question looks stupid ....
Erel B4X founder Staff member Licensed User Longtime User Jan 10, 2023 #8 In that case you can start with TextReader directly: Code: Copy Dim tr As TextReader tr.Initialize(req.InputStream) Dim lines As List = tr.ReadList Upvote 0
In that case you can start with TextReader directly: Code: Copy Dim tr As TextReader tr.Initialize(req.InputStream) Dim lines As List = tr.ReadList
marcick Well-Known Member Licensed User Longtime User Jan 10, 2023 #9 trying to manage everything more efficient, I need to use the j.postbytes command to transmit a list (containing strings) how to convert the list to a byte array ? I'm using this code but get an error B4X: Copy Sub ListToBytes(list As List) As Byte() Dim b(list.Size) As Byte For i = 0 To list.Size - 1 b(i) = list.Get(i) Next Return b End Sub Upvote 0
trying to manage everything more efficient, I need to use the j.postbytes command to transmit a list (containing strings) how to convert the list to a byte array ? I'm using this code but get an error B4X: Copy Sub ListToBytes(list As List) As Byte() Dim b(list.Size) As Byte For i = 0 To list.Size - 1 b(i) = list.Get(i) Next Return b End Sub
E emexes Expert Licensed User Longtime User Jan 10, 2023 #10 marcick said: I need to use the j.postbytes command to transmit a list (containing strings) how to convert the list to a byte array ? Click to expand... Use ByteBuilder. I'd probably start the byte array off with 4 byte Int of the number of strings in the list, and then for each string in the list, add 4 byte int of the string's length followed by the string bytes. Uh, just realised that the string length in bytes could be different to the string length in characters. No problem, though: convert the string to bytes first in a temporary array, then add the length of that temporary array, and then the temporary array, to the final array. It wouldn't surprise me if Serializer did the same thing, but with extra tags to indicate the types List and String. Last edited: Jan 10, 2023 Upvote 0
marcick said: I need to use the j.postbytes command to transmit a list (containing strings) how to convert the list to a byte array ? Click to expand... Use ByteBuilder. I'd probably start the byte array off with 4 byte Int of the number of strings in the list, and then for each string in the list, add 4 byte int of the string's length followed by the string bytes. Uh, just realised that the string length in bytes could be different to the string length in characters. No problem, though: convert the string to bytes first in a temporary array, then add the length of that temporary array, and then the temporary array, to the final array. It wouldn't surprise me if Serializer did the same thing, but with extra tags to indicate the types List and String.
E emexes Expert Licensed User Longtime User Jan 10, 2023 #11 emexes said: then for each string in the list, add 4 byte int of the string's length followed by the string bytes. Click to expand... Or if your strings never contain a newline character aka CRLF aka Chr(10), then forget the lengths, just add a terminator to each string (except maybe the last one, although it'd be "cleaner" if you did) and concatenate them all together. At the other end, to reverse the process, convert the bytes back into a string, then Regex.Split, which handily will should also trim the trailing empty unterminated line. The nice thing about doing it this way, rather than Serialization, is that the intermediate bytes, if they are in a file, are readable with pretty much any text editor (assuming you go with UTF-8 encoding). Upvote 0
emexes said: then for each string in the list, add 4 byte int of the string's length followed by the string bytes. Click to expand... Or if your strings never contain a newline character aka CRLF aka Chr(10), then forget the lengths, just add a terminator to each string (except maybe the last one, although it'd be "cleaner" if you did) and concatenate them all together. At the other end, to reverse the process, convert the bytes back into a string, then Regex.Split, which handily will should also trim the trailing empty unterminated line. The nice thing about doing it this way, rather than Serialization, is that the intermediate bytes, if they are in a file, are readable with pretty much any text editor (assuming you go with UTF-8 encoding).
marcick Well-Known Member Licensed User Longtime User Jan 10, 2023 #12 Thank you emexes, I'll have a look Upvote 0
E emexes Expert Licensed User Longtime User Jan 10, 2023 #13 I am sure a function like this already exists somewhere, but %@#ed if I can find it: B4X: Copy Sub RegexUnsplitStringList(Separator As String, SL As List) As String Dim sb As StringBuilder For I = 0 the SL.Size - 1 sb.Add(SL.Get(I)) sb.Add(Separator) Next Return sb.ToString End Sub B4X: Copy Sub RegexUnsplitStringArray(Separator As String, SA() As String) As String Dim sb As StringBuilder For I = 0 the SA.Length - 1 sb.Add(SL(I)) sb.Add(Separator) Next Return sb.ToString End Sub Upvote 0
I am sure a function like this already exists somewhere, but %@#ed if I can find it: B4X: Copy Sub RegexUnsplitStringList(Separator As String, SL As List) As String Dim sb As StringBuilder For I = 0 the SL.Size - 1 sb.Add(SL.Get(I)) sb.Add(Separator) Next Return sb.ToString End Sub B4X: Copy Sub RegexUnsplitStringArray(Separator As String, SA() As String) As String Dim sb As StringBuilder For I = 0 the SA.Length - 1 sb.Add(SL(I)) sb.Add(Separator) Next Return sb.ToString End Sub
Erel B4X founder Staff member Licensed User Longtime User Jan 10, 2023 #14 Best solution is indeed to use B4XSerializator on the client and server. Upvote 0