How to update an excel sheet from Android App - android

I am trying to establish a simple method for retrieving reference-information from a few cells of an existing excel spreadsheet from an Android app (which is located on a secure company network drive - but could be moved to a secure cloud). Then I wish to add information to that "record" or row of the same spreadsheet.
Is a SQLite database required to do this? or can I pull the reference info directly from the existing excel sheet into a table/list in the app, and then choose to add info to the same sheet in cells relative to the selected reference info/record?
I have looked through the forum and the web and found lots of info on SQLite but nothing that quite fits my requirements.
The idea of this is to be able to find and select a record on the app and then add details (inc. photo's) to that record. So updating the excel sheet with the additional information.
The existing sheet is populated with reference information on a PC and saved to the network drive, to be later added to via the android app as above.
Any help and guidance is much appreciated.

There are two different versions of Excel Sheet file formats used today.
Is the old fashion OLE based file ending: xls
Is the new style XML based file ending: xlsx
Both of them can be processed by java and also on android.
Best practice to work with office docs in Java is the Apache POI project, which can handle both kinds of office formats.
Her is the link to Apache POI for Excel:
http://poi.apache.org/spreadsheet/index.html
What you can do:
If it is OLE based your only choice is to use POI. But POI will always load the hole file into RAM which can be a problem on Android Deviecs with less RAM.
If it is XML based you can directly manipulate the data on the sheet in xml. The file format xlsx or any office doc ending on "x" is a zip file including XML Data and alot of meta informations etc. A file of this kind can be decompressed in a temp folder, you can than read the xml data and manipulate them. After this compress the temp folder into a xlsx file and you are fine.
Or you can also use poi to work with the xlsx file, but also here it loads always the hole file. (I have running applications which push several thousand of rows in excelsheet using the xml technic)
Hope that helps.
P.S. I never tried to use Apache POI on Android, should work but I am not sure. Search on google for examples.
Here are some links regarding XML and Zip technic:
ZipFile in Android SDK: http://developer.android.com/reference/java/util/zip/ZipFile.html
Offical XML Android Docs: http://developer.android.com/training/basics/network-ops/xml.html
Good tutorial about xml parsing using library XMLPullParser: http://developer.android.com/training/basics/network-ops/xml.html
Official XLSX Specs from Microsoft: https://msdn.microsoft.com/en-us/library/dd922181%28v=office.12%29.aspx
Exmple for big Sheets directly manipulating the xml data: https://svn.apache.org/repos/asf/poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/BigGridDemo.java

Related

Android incorrect database encoding on assets folder

I'm trying to implement a simple pre populated database into my assets folder of my Android application which I will then query at a later point. But the problem I'm facing is an encoding issue which I can convert the database inside of Android studio but then it implements a password using cipher encryption.
My current process of adding the database to my project
Firstly I went through the process of building a simple database and table inside of the sqlitebrowser application and made sure that the encoding within the preferences section was set to UTF-8.
http://sqlitebrowser.org - Link to the application which I'm currently using to build the database.
After I was happy with the database I then simply copy and past it into my assets folder.
I'm now presented with the image below (example)
4.My next step is that I convert it to UTF-8 as requested but I thought the sqlite browser would of already put it in this format.
5.The Code will now build the database correctly and I can see it within my data folder.
I then take a copy of the database off the virtual device, but when attempting to open it using sqlitebrowser I'm presented by a window asking for a password (Cipher Encryption). Now when I first built the database at no point did I add a password, so this makes think when Android asked to covert it did it also implement encryption?
Going back to the main question, how can I build a simple database in UTF-8 format which I can then implement into Android Studio assets folder?
At step 2 STOP ignore steps 3 on.
Instead step 3 write an application (perhaps using Android SQLiteAssetHelper, there are numerous tutorials on using SQLiteAssetHelper) to open and use the Database.
Android Studio is not designed to browse/interogate SQLite files, so basically it doesn't have a clue what the underlying data means. However from your screen shot you can see that some of the data does in fact indicate an SQLite file.
For example the following is a screen shot of opening an SQLite Database, (actually created and used in an Android App) in Notepad++ (see any similarities?) :-
e.g. It starts with SQLite format 3, the below mentions tablestudent and then goes on with CREATE TABLE students (_id......
So in all likelihood the data is fine it just needs to be opened/used by something that knows how to interpret the data in the file i.e. SQLite.
What can be seen from your screen shot, is that in all likelihood you have a column named _id.
Therefore your an answer to your question (ignoring opinions such as the best) :-
Hello Zoe what is the best application for building a simple sqlite
database which will be in UTF-8 format that I can then import into my
assets folder?
is, it looks as though you have a suitable tool already (personally I use SQlite Manager for maniuplating and interrogating SQLite Databases, can't say whether SQLite Brwowser is better or worse or the same). All you need to do now is ascertain how to do the new step 3.
regarding your statement
I then past the database into my assets folder which means 3 must be
an image from the assets folder.
That's not the case, all it is is that Android Studio has made an attempt to open the file and perhaps believes that it should be an image. I suspect you could drop in a PDF or Word document (might have to change the extension to fool Android Studio) and it may well come up with a similar response. i.e (not that I've tried this) it may be that Android Studio has not been designed to read in MS Word or PDF documents, so knows nothing about them.
Ok, tried this now, here's part of a PDF file (extension renamed to xxx, as AS opened it as a PDF with pdf extension) :-

Android - Google Drive REST API - Adding a row to a CSV file

This question concerns adding a new row to a CSV file that exists in Google Drive using the Google Drive REST API.
On my Android device, I have a CSV file that I am building locally. If I add a row to the local CSV, I want to also add that row to the CSV that resides on Google Drive.
I've got the fileId of the CSV, and I can PUT the file to do a direct replacement, but I'm trying to save bandwidth as the file size grows.
I have been looking into JSON Patch as the transport to perform this, but I cannot find a concrete example after looking for days. For instance, how does JSON Patch write to the CSV file? Is the "path:" parameter the column header? Is a "op", "add" needed for each column?
I just need to pointed in the right direction.
To my best knowledge, it is not possible. You are trying to append (modify) the content of a file and the only way I know of in both the REST Api and the GDAA is to get the content, modify it and upload. It is possible that GDAA may (one day) internally do some diff / incremental optimization, but I doubt it.
My rational for this guess is that the content is being shipped as base64-ed, gzip-ed, ... binary stream with no embedded knowledge of the mime type, so the 'append' functionality would get quite complex.
The PATCH functionality you'r looking into deals only with METADATA (title, mime, modi-dates, parentIDs, etc...). See the fields available in Try it! on the bottom of this page.
Good Luck
In case anyone else comes across this question, an alternative solution (which doesn't involve switching to using a Google Sheets file) would be to move the read-modify-write API calls to a small service hosted on Google Apps Script and call that service from your application using the recently-announced Execution API.
You would call the hosted script with the new row to be appended to the file, and the script (running in the cloud and with very fast access to the Drive API) would get the file content, append the new row, and then save the file back to Drive. This would save bandwidth between your mobile application and the hosted script.

What is the preferred way of importing/exporting data into Android app

I am making a vocabulary app to learn hungarian. The app has a database with words in two languages. The words should be entered as I meet them in the daily life and then I use the app to exercise the words.
Now I want to be able to enter the words on the computer, and import it to my app. Or share my words with a friend and thus export it from the app somehow.
As a windows programmer I am used to think in terms of files. I would make a simple file format or just use csv or xml files. But I see now when making Android apps that the file approach is not the thing. I don't get any file dialogs included with the api and when I search for how to import files it is hard to find an answer.
So my question is: What is the android/touch way of importing/exporting this kind of data?
EDIT: To clarify my question: Many windows programs have a way of importing data when you press File->Import and you get a file dialog where you can choose the file with the data you want to import. Since I don't find any file dialog or many examples on how to import files I recon there must be another more convenient way in android/touch devices. Maybe something with Content Providers. My vocabulary app is just an example.
I did not understand your question clearly but my suggestion to you is, if you have large amount of data:for example saving data of an employ,so you can use the Sqlite Database in android and connect it to your Desktop Database (for example you can create in xampp).Then You can send and recieve data.
Since you want to allow the users to enter the words in a Spreadsheet, you should give them an option to import data from Excel sheets, provided they create the sheets in a format specified by you. You can learn how to read XLS files programmatically online, here are some references:
http://www.cuelogic.com/blog/creatingreading-an-excel-file-in-android/
How to read data from XLS (Excel) file [Java, Android]
Read Excel file in android
After parsing the XLS sheet, you can insert them in an SQLite database. You can have all you want to know about SQLite in Android here:
http://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html
http://www.vogella.com/tutorials/AndroidSQLite/article.html

Using an online .txt file as a data source

I am building an Android app for a client and most of the data that i need is contained in an online .txt file attached to my clients website. I've never used an online .txt file as a data source before and don't really know where to begin?! Can anyone point me in the direction of a good tutorial on the subject.
Many Thanks in advance
P.S. I haven't asked whether it's possible because i have assumed it is due to the fact you can use an internal .txt file as a data source
I think the best approach is to download the file on the device and then read it like a normal file. If the file changes on a period of time, then configure the app to download and read the file and then update the local info in the app.
I don't think you can use an online txt as a DataSource, but you can implement this so you have an abstract source for your file, and then just call read on it.
Expose the txt/xml file over web,if you want to get it down to phone use URL loader and load it to the phone and operate if you want to use it online (like others may also be using it) it will be a bit complex in order to deal with data coming from more then one source but possible. clear you question a bit more.

Create an output document from Android App

I have an android app where I will be capturing various information in different forms and storing into the SQL lite database for tracking/viewing purposes. I want to give the option of exporting the information into a RTF/PDF/Doc and give the option of sending it thru email.
I looked at various similar questions posted here earlier but didnt get a definitive answer. I saw the Android PDF Writer library http://sourceforge.net/projects/apwlibrary/ but this seems very basic. I considered iText but I think there would be issues with licensing if in future I want to sell this app..
Basically I want to define a template document with a structure that will be copied and content added to it based on what the user wants to export...
Any help is greatly appreciated...
I wanted some elegant solution where I can store a template in the assets folder and replace whatever I want to create the output document. Finally I went with html. I created a html template and put it into the assets folder. After that it was as simple as read assets, read db, do string.replaceall and write the output html and email it out.....
OpenOffice.org's Universal Network Objects (UNO) interface to programmatically generate MS-Word compatible documents (*.doc), as well as corresponding PDF documents.
its basically java so it should work on android too.

Categories

Resources