Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

adding more than one sheet to an excel document #2

Closed
mehmetyaman opened this Issue · 13 comments

5 participants

@mehmetyaman

it is not possible to add multiple sheets to a document, documents constructing with a single sheet but if you need more than one on a single excel document you have no solution for this.

@jakubnabrdalik

True. It's easy to implement though.
The only problem is to how to keep it simple (and possibly keep the current behavior) for single sheet, and at the same time allow for many sheets.
Do you have any suggestions how would you like the API to look like for this? How would you like to use it?

@brian428

Late to this, but could it be as simple as generating separate xls files then doing a merge to create one final file before downloading?

@orlandobcrra

Hi all,
I would like have this feature,
What do you think if we use something like:

new XlsxExporte('/tmp/report1.xlsx').with {
nameOfSheet1{
putCellValue(1, 1, 'hello')
}
nameOfSheet2{
putCellValue(1, 1, 'world')
}
}

or something like that, and if the sheet isn't specified, all data will be written in the 'default' sheet
??

Regards

@jakubnabrdalik

Good idea, I like it. I would try to keep it easy on the compiler/IDE though, with something like this

new XlsxExporte('/tmp/report1.xlsx').with {
sheet('nameOfSheet') {
...
}
sheet('otherSheet') {
...
}
}

And if no sheet is specified, the default would be used.

This would give us IDE support out of the box (sheet as a method of the worksheet).

@jakubnabrdalik

@brian428 We could also go this way, but I think what orlandobcrra proposed is a bit more... natural?

@brian428

Oh, either would be good. I was just thinking that generating two separate files and merging them would be the easiest short-term option. I've written a plugin myself (the Grails CoffeeScript compiler) and deal with numerous other Github projects, so I know how tight time can be. :-)

Since I know POI can merge files, and I know your plugin will generate an Excel file, I figured just taking that and sticking them together would be a pretty simple addition. Probably just exposing one new method, really. But whatever works!

@brian428

To add, I suppose the only advantage I could see to going the merged-file approach would be the ability to break up the creation of each sheet. I could envision a situation where different sheets have very different logic to build, and having to do it "all in one place" could be cumbersome. With separate sheets, you can create each one however you want to, and then just merge them when they're all ready. But I'm not sure if that's a major concern.

@brian428

On a roll here, but one more thought: with separate files, one of the sheets could even be a preexisting or static file that gets added in along with other dynamic sheets. I'll stop now. Back to work with me.

@jakubnabrdalik

Perhaps we can implement both. I'll see what I can do (or send me a pull request if you have a while)

@orlandobcrra

I could help in that (sheet as a method of the worksheet) - please give me a class name where I should look and I think I'll sort it out.

@jakubnabrdalik

@orlandobcrra
The entry point, and the object where the state is kept, is XlsxExporter. All the methods are defined on this class, but most of them are split into their own classes (abilities) using Mixin and Category annotations (vide: abilities package). This makes it more readable/manageable.

Right now XlsxExporter has a:

protected Sheet sheet 

property. That will have to be changed.

Please write tests for all the new features. There are a lot of them already, so it should be a problem. I'll be glad to help if you have any more questions.

@joeRinehart

All three of us here in my team (brian428, and another lurker...) need this, so I've put something together that maintains a fairly natural API (without breaking the existing). Pull request submitted (#15)

@jakubnabrdalik

Merged. Let me know if it works for you. I had to change a few things, but I've tried to keep all your features.
Thanks a lot for the implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.