Ask Ben: Updating An Excel Document More Than Once With The POI Utility

Posted August 6, 2008 at 9:04 AM

Tags: ColdFusion, Ask Ben

Does this utility [POI] include a way to continue to add data to the spread sheet after the first addition? Thanks again for all of your help.

Yes it does. Well, sort of. The POI utility ColdFusion custom tags allows you to dictate a "template" to be used. This template is an existing Excel file whose contents are read in without alteration. Then, you can make changes to the existing Excel data as you see fit. So, if you treat each file as a template, you can continue to make as many updates as you want.

What the POI ColdFusion custom tags do NOT do is pick up where they left off. So for example, if you wrote 100 rows then closed the file. Then opened it again and wrote 100 rows - you'd end up with a file that has 100 rows in it, not 200. If your intent is to have 200 rows, then perhaps we can update the functionality of the tags. Because the "Index" attribute of the rows and cells allows you to manually output data in position you like, I want to avoid the idea of an "append" action:

 Launch code in new window » Download code as text file »

  • <poi:sheet action="append">

Besides, if you really are using the POI custom tags to populate a formatted template, you aren't really appending.

What about something like a CALLER-scoped variable that has information about the read-in Excel file? Something like this:

 Launch code in new window » Download code as text file »

  • <poi:sheet>
  • <poi:row index="#(POI.InitialRowCount + 1)#">
  • <poi:cell ... />
  • </poi:row>
  • </poi:sheet>

Here, in the context of the current Sheet, POI.InitialRowCount stores the number of rows that were already in the Excel file at the time of instantiation. This way, you could tell the "Index" tracking to pick up after the last row of the read-in Excel file.

Do you think something like that might be useful?

Download Code Snippet ZIP File

Post Comment  |  Ask Ben  |  Print Page



Learning ColdFusion 9 - ColdFusion 9 tutorials, samples, examples, demos

Reader Comments

Ana
Aug 8, 2008 at 5:41 PM // reply »
3 Comments

In most cases this solution would be perfect. In my case the row numbers are part of the template design (excel row numbering is turned off for aesthetic purposes), therefore, when the excel file is read there will be data in Column 1 row 1 thru ...


Aug 8, 2008 at 6:30 PM // reply »
7,572 Comments

@Ana,

I am not sure that I am following you exactly. Are you saying that your using row numbers in a way that this would not work?


Ana
Aug 12, 2008 at 6:59 PM // reply »
3 Comments

Yes. From my understanding of what you wrote is that the IntitialRowCount() would check the for the last row that has data. Is that correct? If so the author of the excel file as placed row numbers in column1:row1 with a style. That's why I think what you are saying wouldn't work for me.


Post Comment  |  Ask Ben

Recent Blog Comments
Mar 22, 2010 at 3:08 AM
Ask Ben: Selecting XML Attributes Given Other XML Attributes
Thanks for the response. I finally discovered that I was getting this error because I had cfsetting enablecfoutputonly="yes" in Application.cfc, and was neither setting it to false elsewhere nor brac ... read »
Mar 21, 2010 at 8:57 PM
The Bourne Ultimatum Starring Matt Damon And Julia Stiles
late to the party, but my observation is this: rewatch carefully for the platonic nature of the relationship between nicki and jason. she never flirts with him. he never comes on to her. they alway ... read »
Mar 21, 2010 at 7:40 PM
Is Simulating User-Input Events With jQuery Ever A Good Idea?
A couple of things. One you embed the initial state of of more-info in the CSS. IMHO, that behavior should be in jQuery: moreInfo.hide(); It shows that the behavior your toggling and closing is mor ... read »
Mar 21, 2010 at 3:59 PM
Exploring ColdFusion Component Runtime Class Properties And Serialization
@Elliott, according to Ben's experiment, serializeJSON() doesn't access the private data by default - it doesn't even access the getHair() method - so trying to clone a Girl.cfc via serializeJSON/des ... read »
Mar 21, 2010 at 3:49 PM
Ask Ben: Javascript String Replace Method
I'm confused a bit by what you are asking, but if had this sentence: The color, red, is in the style statement; style: red;. and wanted to remove all or change all of the commas, colons, and semi-c ... read »
Mar 21, 2010 at 3:13 PM
Ask Ben: Javascript String Replace Method
I am trying to make a java program to count the number of times that these punctuation marks occur in a body of text: , : ; . ! - ' " ? / \ I am using this piece to ferret out the commas: numcommas ... read »
Mar 21, 2010 at 11:13 AM
A New Wrist Pain
@chiropractor suwanee, Spoken like someone trying to sell something. Other than for minor, temporary relief from some back pain, chiropractic treatment is nothing but placebo effect and quackery. ... read »
Mar 21, 2010 at 6:32 AM
ColdFusion CFPOP - My First Look
Apologies... The field name in the db for C. is "BounceCode" It stores the code / message which is returned in the email. Sorry for the confusion. ... read »