Results 1 to 4 of 4
Thread: ROW Duplication
- 01-15-2017, 07:31 PM #1
Member
- Join Date
- Jan 2017
- Posts
- 3
- Rep Power
- 0
ROW Duplication
Background:
1500 columns ( calendar of ca. 3 years = ~1500 days)
1000 rows
in Total ~1.5 Mio cells
ROW = 0
skip
ROW = 1
I am creating for row=1, 1500 columns, i.e. 1500 cells
Each cell is empty.
I am just changing the bg-color.
- Weekend cells are grey background
- Weekdays cells are white background.
So far so good! If I save the Excel file, I got what I need.
ROW = 2...1000 HELP
Now I wanna apply this for the next 1000 rows aswell.
But WHAT is the fastest way to do this?
I tried followinig copy-approach, but not successfully:
PHP Code:final CellCopyPolicy defaultCopyPolicy = new CellCopyPolicy(); defaultCopyPolicy.createBuilder(); defaultCopyPolicy.setCondenseRows(false); defaultCopyPolicy.setCopyCellFormula(false); defaultCopyPolicy.setCopyCellStyle(true); defaultCopyPolicy.setCopyCellValue(false); defaultCopyPolicy.setCopyHyperlink(false); defaultCopyPolicy.setCopyMergedRegions(false); defaultCopyPolicy.setCopyRowHeight(false); defaultCopyPolicy.setMergeHyperlink(false); for (int j = 2; j <=1000; j++) { sheet.copyRows(1, 1, j, defaultCopyPolicy); }
Afterwards it freezes during saving the file:
PHP Code:FileOutputStream out = new FileOutputStream(new File(targetFile)); workbook.write(out); out.close();
(Taskmanager shows 2GB)
- 01-15-2017, 08:27 PM #2
Re: ROW Duplication
Two observations:
1) You are using the builder wrong. It won't influence the outcome, but in the future it may affect any builder you create:
Java Code:CellCopyPolicy policy = new CellCopyPolicy().createBuilder() .cellFormula(false) .cellStyle(true) .cellValue(false) .condenseRows(false) .copyHyperlink(false) .mergedRegions(false) .mergeHyperlink(false) .rowHeight(false) .build();
Can you provide the full source, so I can try it myself?"It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2™ © 2013
- 01-16-2017, 12:38 PM #3
Moderator
- Join Date
- Apr 2009
- Posts
- 13,541
- Rep Power
- 27
Re: ROW Duplication
For POI (and Excel, to be honest) you want to keep the number of styles down. There is a limit.
Since all you are doing is colouring a column of cells, then select that column and apply the colour to all of them at once.
That way you only have 1500 things to do.
In fact, since you know weekends are two days next to each other, you can cut that down again...and finally, just select all 1500 columns at the start and apply white to them in one go.Please do not ask for code as refusal often offends.
** This space for rent **
- 01-21-2017, 03:50 PM #4
Member
- Join Date
- Jan 2017
- Posts
- 3
- Rep Power
- 0
Similar Threads
-
Code duplication - must be a better way?
By Dark Knight in forum New To JavaReplies: 11Last Post: 03-26-2014, 01:05 AM -
JComboBox false duplication
By rookiecoder in forum AWT / SwingReplies: 8Last Post: 09-26-2012, 12:08 PM -
Compare two Arrays, checking for duplication
By Redefine12 in forum New To JavaReplies: 4Last Post: 02-03-2012, 10:57 PM
Bookmarks