Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FastODS on Android app #180

Closed
SrHalf opened this issue Apr 9, 2020 · 3 comments
Closed

FastODS on Android app #180

SrHalf opened this issue Apr 9, 2020 · 3 comments
Labels

Comments

@SrHalf
Copy link

SrHalf commented Apr 9, 2020

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
Copy link
Owner

jferard commented Apr 9, 2020

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
Copy link
Author

SrHalf commented Apr 9, 2020

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
Copy link
Owner

jferard commented Apr 9, 2020

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.

@jferard jferard closed this as completed Apr 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants