Modify data in excel using jxl without creating copy - android

I'm trying to use an excel file as a database and the app constantly needs to read and modify the file. As explained in this Q&A, it is necessary to create a copy of original excel file and all the modification has to be done there. Is there anyway to modify the excel file without creating a copy because I'll be using the file name at another instance to read it.
Also, I'd like your opinion on which one would be efficient as a database for offline access? An android sqlite or excel file ?

Related

Can We Store Our SQlite DataBase Into PDF or Excel File?

I'm fairly new to Android, I'm created simple CRUD operation app... now i want to save my data base into SD card in pdf or excel format.. can we do this .. if yes.. then how to achieve it or not.. then why?
Of course no ?
why use PDF or Excel !!!
You will not able to CRUD any more on this file ? even if we suppose you use a 3rd lib to update this file on android , but why use a file , it will be hard and even very slow compared to sqlite..
and how to deal with relation between record in your database ?
I advise you to use sqlite or any ORM in android instead of file like PDF or Excel... and you can export from database later a PDF/EXCEL/etc ...

Converting a CSV file into an SQLite .db file

I have a CSV file and am trying to convert it into an SQLite .db file so that I can use it in my Android app.
I am aware of methods I can use within the app to convert a CSV placed in the assets folder to an SQLite database within the Android app (e.g. by reading all lines from the CSV file and adding them to the SQLite database), however I want to generate a .db file outside of the app.
The reason I would prefer to do this is because I have several CSVs at around 5 MB each (over 350,000 rows) and so it would take too long to read them all and put them into a new SQLite database in the Android app.
I'm hoping that being able to put my .db files into the assets folder and using the android-sqlite-asset-helper library to access the data from these will be faster.
I have tried tools like a CSV to SQL converter which uses the data from the CSV file you upload to generate an SQL script (i.e. DROP then CREATE then INSERT), but I'm not sure what I need to do with the .sql file to make a .db out of it.
There are also some ways of doing this (I think) I found on Stack Overflow with commands, but I am unsure of how these work and how I use the commands.
So I am asking how I can convert a CSV file into an SQLite database. What is the best method?
Out of curiosity, have you tried creating the database from within the SQLite CLI? Facilities for CSV import exist: https://www.sqlite.org/cli.html#section_8 followed up with a quick ".save output.db" may accomplish what you need.

Get a reference to a file saved at compile time

I have a text file which I'll be using to populate my database. The easiest way I found to use this file is using .import statement of SQLite. The statement will be something like this.
.import <myFileName> <myTableName>
However, I don't know where to save this text file. The most basic choice is res/raw folder. But then how to get a reference to this File ?
I must emphasize on the fact that I want a reference of the file and not read it.
Thanks.
You can in general cannot get real file handles of files that do not exist. Ressources and Assets are compiled into your apk, and thus no regular files.
If you wish to ship your application with a database, you can use the asset folder. There is a related question about that. The basic method is that you create the whole database at compile-time (using some tool for sqlite databases, for example SQLite database browser) and ship that database file as asset. Then you can extract the database file from assets and use the newly created database file.

Reflect Data in the Excel sheet to the android app

I am new to android development. I have two questions:
I have an Excel sheet as a database for my data. I want to display that data in my android application. How can I do it? Do I have to use SQLite database? If yes, then how?
If there are any changes in the Excel sheet in the future, then how would be these changes be reflected in the application?
Thanks in advance for all the help.
To read excel file in android, you should use some excel library such as JExcelApi, Apache POI.
after reading it, you can write them into SQLite dababase to reduce excel parsing time.
when you parse excel file, you save the file's last modified time to text file or preferences and whenever your app runs, comare them and update it if last modified time is different.
WelCome to Stack overflow!
I have an excel sheet as a database for my data.I want to display that data in my android
application.How can i do it? do i have to use sqlite database?if yes then how?
Here is example how read .xls file from server (you can also read file from SDCARD)
assume your .xls is like below
then you have to create sqlite database and create table with field(Item Number,Description,Price,Quantitiy) you can also create fields depend on .xls file.
after read data from .xls insert in to sqlite database
Note: with xls some times its not working well if file format is not well. i have developed app which work with xls,csv. so, i ll sagest you to use csv insted of xls which is best option. how read csv file and how write csv file.
And if there are any changes in the excel sheet in the future then how would be these changes be reflected in the application
any changes in xls then you have to update you sqlite database.(its easy if you have developed code to create table dynamically depend on xls file column then its good)
How to use sqlite in android Basic
How to use sqlite in android.

Implementing copy of Android App DB file for backup/restore is this proper way?

I am using java methods to copy my application sqlite db from the application data directory to a folder in sd and have code to restore these file back to the application data directory. Is this a proper way of doing it? Are there potential errors or data corruption since it's a database file?
It's perfectly fine to do so. SQLite files do not have any dependencies to other files, so copying them to SD card will achieve your goal. You can check the contents of SQLite files with SQLite browser if you want to make sure.
I would suggest exporting your DB to JSON format, and save that on an external location for backup/restore. That way, you can control the data you backup (maybe you want to skip backing up some confidential data?) and you can allow advanced restore features (restore only the data and not the preferences).
In order to do that, you need to represent every table with a class (if your using ORM - this is needed anyway), and then just use one of the JSON libraries, like "Gson", to get the JSON representation of the DB. After that, you can save it to some file wherever you'd like.

Categories

Resources