ASF Bugzilla – Attachment 33013 Details for
Bug 58260
Formatting Fails after 32768 Rows. Works again after 65538
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
stand alone program that creates an excel document with 70K rows
Sample.java (text/plain), 2.37 KB, created by
Craig
on 2015-08-18 20:49:54 UTC
(
hide
)
Description:
stand alone program that creates an excel document with 70K rows
Filename:
MIME Type:
Creator:
Craig
Created:
2015-08-18 20:49:54 UTC
Size:
2.37 KB
patch
obsolete
>import java.io.BufferedReader; >import java.io.File; >import java.io.FileOutputStream; >import java.io.FileReader; >import java.io.IOException; >import java.util.ArrayList; > >import org.apache.poi.ss.usermodel.CellStyle; >import org.apache.poi.xssf.streaming.SXSSFCell; >import org.apache.poi.xssf.streaming.SXSSFRow; >import org.apache.poi.xssf.streaming.SXSSFSheet; >import org.apache.poi.xssf.streaming.SXSSFWorkbook; >import org.apache.poi.xssf.usermodel.XSSFCellStyle; > >public class Sample { > public static void main(String[] args) throws IOException{ > > createSampleExcelDocumentFromFile(); > checkRowFormatting(); > } > > public static void createSampleExcelDocumentFromFile() throws IOException{ > int rowCount = 0; > ArrayList<String> rowList = new ArrayList<String>(); > > > rowList = getRowInputFromFile(); > > //Create workbook and worksheet > SXSSFWorkbook wb = new SXSSFWorkbook(); > SXSSFSheet worksheet = (SXSSFSheet) wb.createSheet("sample"); > > System.out.println("Running..."); > //Loop through and add all values from array list > for(int i=0; i<rowList.size(); i++){ > //Create new row > SXSSFRow row = (SXSSFRow) worksheet.createRow(rowCount++); > > //Create cell style > CellStyle style = wb.createCellStyle(); > style.setAlignment(XSSFCellStyle.ALIGN_RIGHT); > > //Create cell > SXSSFCell cell = (SXSSFCell) row.createCell(0); > > //Set cell style > cell.setCellStyle(style); > > //Set cell value > if(rowList.get(i).matches("\\d+(\\.\\d{1,2})?")){ > double value = Double.parseDouble(rowList.get(i)); > cell.setCellValue(value); > } > else{ > cell.setCellValue(rowList.get(i)); > } > > } > //add column width for appearance sake > worksheet.setColumnWidth(0, 5000); > > // Write the output to a file > System.out.println("Writing..."); > FileOutputStream fileOut = new FileOutputStream("sample.xlsx"); > wb.write(fileOut); > fileOut.close(); > > System.out.println("Done"); > } > > public static ArrayList<String> getRowInputFromFile() throws IOException{ > File fileIn = new File("sample.txt"); > BufferedReader br = new BufferedReader(new FileReader(fileIn)); > > String line = null; > ArrayList<String> rowList = new ArrayList<String>(); > > while ((line = br.readLine()) != null) { > rowList.add(line); > } > br.close(); > return rowList; > } > > public static void checkRowFormatting(){ > //Add code here > } >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 58260
: 33013 |
33014