jferard / fastods

A very fast and lightweight (no dependency) library for creating ODS (Open Document Spreadsheet, mainly for Calc) files in Java. It's a Martin Schulz's SimpleODS fork
GNU General Public License v3.0
36 stars 6 forks source link

FastODS on Android app #180

Closed SrHalf closed 4 years ago

SrHalf commented 4 years ago

Can I use FastODS to export my list of data on Android app? Currently I'm exporting only to CSV, but I wana export in more formats, and FastODS seems interesting. Any limitation? How can I use it properly?

jferard commented 4 years ago

Hi. I never tried FastODS on Android. There's a reasonable hope it works because there's no runtime dependency beyond the standard library. (Dependencies are for tests only.) If you try it, please let me know the outcome so that I can update the README.

SrHalf commented 4 years ago

Salut, êtes-vous français ? Je parle un peu ta langue ! Haha

So, I have implemented FastODS on my Android project and it worked pretty well. I didn't test it out on other devices because I don't have another one available right now, but I intend to do this. The ODS file generated is perfectly readable on Google Sheet for Android and Microsoft Excel for Android.

I'm using: OS: Ubuntu 18.04.4 LTS IDE: Android Studio 3.6.1 Device: Android 9 Pie

This is how I did it. First of all, I put it on gradle.build: implementation 'com.github.jferard:fastods:0.7.2'

And my method for exporting process is (in Kotlin, but there's no significant difference):

` fun exportToODS(tableName:String){

val folder = File(Environment.getExternalStorageDirectory(), "Exported")
if(!folder.exists())
    folder.mkdir()
val odsFile = File(folder, "MyList.ods")
val writer = OdsFactory.create().createWriter(odsFile)
val document = writer.document()
val table = document.addTable(tableName)
//
val items = //Select all items of my list..
for(i in 0 until items.size){
    val item = items[i]
    val row = table.getRow(i)
    //
    row.getOrCreateCell(0).setStringValue(item.valueOne.toString())
    row.getOrCreateCell(1).setStringValue(item.valueTwo.toString())
    row.getOrCreateCell(2).setStringValue(item.valueThree.toString())
    row.getOrCreateCell(3).setStringValue(item.valueFour.toString())
    row.getOrCreateCell(4).setStringValue(item.valueFive.toString())
    row.getOrCreateCell(5).setStringValue(item.valueSix.toString())
    //
    //More cell values..
}
//
writer.save()
writer.close()

} ` I didn't publish the update of my app yet, because I have a lot of work to do, but I wanted to post it that FastODS work fine on Android.

Great job!

jferard commented 4 years ago

Yeah I'm french - je suis français. Thanks for the feedback. I'll write a line in the README to say that FastODS works on Android.