Quantcast
Channel: Java Programming Forum - Learn Java Programming - Apache POI
Viewing all articles
Browse latest Browse all 120

ROW Duplication

$
0
0
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: :(doh):

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);               
}

The for-loop takes 45 seconds.
Afterwards it freezes during saving the file:
Code:

FileOutputStream out = new FileOutputStream(new File(targetFile));
                       
workbook.write(out);
out.close();

WHAT is the fastest way to do this?

(Taskmanager shows 2GB)

Viewing all articles
Browse latest Browse all 120

Trending Articles