Export sqlite database file into XML and then into

2019-03-29 07:03发布

问题:

I am trying to do this task from the past 12 hour, but still am not able to do this...Now I have an sqlite database file named "testDatabase.db" into the sd card as a backup file..Now I want to open the database into the spreadsheet format so that the end user can access the database and store this spreadsheet database into his system and then further for printout and for other purpose..

I studied some of the tutorials in which It was written that u can firstly convert ur database file into XML and then export this file to excel format..

But am not able to do export my databse file into XML format...As according to my requirement I want on button click my database file should be converted into xml format so that the end user can use it.

Thanks..

回答1:

As far as I know, there is no "one click way" of doing that. You can either create .bat script to export each table into a CSV or html table (commands can be found here), and then import them into excel.
Or you can download a software like sqlite database browser open your .db file and then export each table into a csv file.



回答2:

I know this might be a little late but in case someone else searches for this and see's this question the best answer would be to export the database as a CSV (comma delimited) file.

sqlite3 has a function just for this called "quote". You can read more about it here:

http://www.sqlite.org/lang_corefunc.html#quote

example:

create table t1 (c1 char, c2 int);

insert into t1 values ('a hi', 1);

insert into t1 values ('b hello', 2);

select quote(a) || ',' || b from t1;

this would return: 'a hi',1 'b hello',2

There are other ways to use the quote function but it really depends on your data and how you want to use it.



回答3:

Does the transform have to happen on the Android device?

If you're more flexible about how it's done, you can give the user the sqlite database file and they can import the data via the sqlite ODBC driver: http://www.ch-werner.de/sqliteodbc/



回答4:

While it's not technically a generation of XML, you can easily skip that middle step and generate an Excel spreadsheet directly from the command line.

Most spreadsheet applications can import HTML Tables and handily sqlite3 has a command-line option to export queries in that format.

echo "<HTML>
<BODY>
<TABLE>" > spreadsheet.xls

sqlite3 -html sqlite.db "select * from table;" >> spreadsheet.xls

echo "</TABLE>
</BODY>
</HTML>" >> spreadsheet.xls

For instance, when opening this spreadsheet.xls file in LibreOffice I'm presented with the option to Import. Clicking 'Yes', the file opens just like a normal spreadsheet. You can then adjust formatting and resave as necessary to make it a true XML-zipped Excel file.