ASF Bugzilla – Attachment 31431 Details for
Bug 56307
Ordering in autofilter crash the excel
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
Source code file
ExportTest.java (text/plain), 2.67 KB, created by
Ivan Skultety
on 2014-03-24 04:26:07 UTC
(
hide
)
Description:
Source code file
Filename:
MIME Type:
Creator:
Ivan Skultety
Created:
2014-03-24 04:26:07 UTC
Size:
2.67 KB
patch
obsolete
> >import java.io.File; >import java.io.FileInputStream; >import java.io.FileNotFoundException; >import java.io.FileOutputStream; >import java.io.IOException; >import java.util.ArrayList; >import java.util.List; > >import jxl.Workbook; >import jxl.write.Label; >import jxl.write.Number; >import jxl.write.WritableSheet; >import jxl.write.WritableWorkbook; > >import org.apache.poi.hssf.usermodel.HSSFSheet; >import org.apache.poi.hssf.usermodel.HSSFWorkbook; >import org.apache.poi.ss.usermodel.Cell; >import org.apache.poi.ss.usermodel.Row; >import org.apache.poi.ss.util.CellRangeAddress; > >public class ExportTest { > > public static List<String[]> data; > > public static void main(String[] args) { > try { > // test data > data = new ArrayList<String[]>(); > data.add(new String[] {"Emp No.", "Name", "Salary"}); > data.add(new String[] {"1", "John", "15000"}); > data.add(new String[] {"2", "Sam", "8000"}); > data.add(new String[] {"3", "Dean", "7000"}); > > // write Sheet > String filename = "E:\\new.xls"; > writeJxlSheet(filename); > writePoiSheet(filename); > } catch (Exception e) { > e.printStackTrace(); > } > } > > public static void writeJxlSheet(String filename) throws Exception { > WritableWorkbook workbook = Workbook.createWorkbook(new File(filename)); > WritableSheet sheet = workbook.createSheet("Jxl sheet", 0); > > // write to excel sheet > for (int rownum=0; rownum<data.size(); rownum++) { > int cellnum = 0; > for (String value : data.get(rownum)) { > sheet.addCell(new Label(cellnum++, rownum, value)); > } > } > > if (workbook != null) { > workbook.write(); > workbook.close(); > } > } > > public static void writePoiSheet(String filename) throws Exception { > FileInputStream file = new FileInputStream(new File(filename)); > HSSFWorkbook workbook = new HSSFWorkbook(file); > HSSFSheet sheet = workbook.createSheet("Poi sheet"); > > // write data > for (int rownum=0; rownum<data.size(); rownum++) { > Row row = sheet.createRow(rownum); > int cellnum = 0; > for (String value : data.get(rownum)) { > Cell cell = row.createCell(cellnum++); > cell.setCellValue(value); > } > } > > // set filter > sheet.setAutoFilter(CellRangeAddress.valueOf("A1:C40")); > > // write to file > try { > FileOutputStream out = new FileOutputStream(new File(filename)); > workbook.write(out); > out.close(); > System.out.println("Excel written successfully.."); > > } catch (FileNotFoundException e) { > e.printStackTrace(); > } catch (IOException e) { > e.printStackTrace(); > } > } >}
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 56307
: 31431