poi-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject [Bug 60838] New: office2013 AP after column style will be lost
Date Thu, 09 Mar 2017 02:44:07 GMT
https://bz.apache.org/bugzilla/show_bug.cgi?id=60838

            Bug ID: 60838
           Summary: office2013 AP after column style will be lost
           Product: POI
           Version: 3.12-FINAL
          Hardware: PC
            Status: NEW
          Severity: normal
          Priority: P2
         Component: HSSF
          Assignee: dev@poi.apache.org
          Reporter: 171207538@qq.com
  Target Milestone: ---

Created attachment 34809
  --> https://bz.apache.org/bugzilla/attachment.cgi?id=34809&action=edit
example

Hi:
    I have a question. Execute the following code, office2010 is no problem,
but for office2013 AP after column style will be lost.  I use poi version 3.12.

Code:

// for test
        public static void main(String[] args) {
                String[][] data = new String[][] { { "123", "456", "789",
"012","123", "456", "789", "012","123", "456", 

"789", "012","123", "456", "789", "012","123", "456", "789", "012","123",
"456", "789", "012","123", "456", "789", 

"012","123", "456", "789", "012","123", "456", "789", "012","123", "456",
"789", "012","123", "456", "789", "012","123", 

"456", "789", "012","123", "456", "789", "012","123" }, { "123", "456", "789",
"012","123", "456", "789", "012","123", 

"456", "789", "012","123", "456", "789", "012","123", "456", "789",
"012","123", "456", "789", "012","123", "456", "789", 

"012","123", "456", "789", "012","123", "456", "789", "012","123", "456",
"789", "012","123", "456", "789", "012","123", 

"456", "789", "012","123", "456", "789", "012","123" }, {  "123", "456", "789",
"012","123", "456", "789", "012","123", 

"456", "789", "012","123", "456", "789", "012","123", "456", "789",
"012","123", "456", "789", "012","123", "456", "789", 

"012","123", "456", "789", "012","123", "456", "789", "012","123", "456",
"789", "012","123", "456", "789", "012","123", 

"456", "789", "012","123", "456", "789", "012","123"} };
                exportExcel(data, "E:\\excelutil-write.xls");
        }

public static boolean exportExcel(String[][] data, String filePath) {
                if (data == null || data.length == 0) {
                        return false;
                }
                boolean flag = true;
                HSSFWorkbook workbook = new HSSFWorkbook();
                try {
                        File file = new File(filePath);
                        if (file.exists()) {
                                file.delete();
                        }
                        FileOutputStream outputStream = new
FileOutputStream(file);
                        Sheet sheet = workbook.createSheet();
                        workbook.setSheetName(0, "sheet1");
                        Row row = null;
                        Cell cell = null;
                        int rowCount = data.length;
                        int colCount = data[0].length;
                        CellStyle style = workbook.createCellStyle();
                        style.setBorderBottom(CellStyle.BORDER_THIN);
                        style.setBorderLeft(CellStyle.BORDER_THIN);
                        style.setBorderRight(CellStyle.BORDER_THIN);
                        style.setBorderTop(CellStyle.BORDER_THIN);
                        style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
                        style.setAlignment(CellStyle.ALIGN_CENTER);
                        List<CellStyle> dList = new ArrayList<CellStyle>(); 
                        for (int i = 0; i < colCount; i++) {
                                CellStyle dstyle = workbook.createCellStyle();
                                dstyle.cloneStyleFrom(style);
                                dstyle.setAlignment(CellStyle.ALIGN_CENTER);
                                dList.add(dstyle);
                        }
                        for (int i = 0; i < rowCount; i++) {
                                row = sheet.createRow(i);
                                for (int j = 0; j < colCount; j++) {
                                        cell = row.createCell(j);
                                       
cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                                        cell.setCellValue(data[i][j]);
                                        CellStyle cStyle = dList.get(j);
                                        //cStyle.cloneStyleFrom(dList.get(j));
                                        cell.setCellStyle(cStyle);
                                }
                        }
                        workbook.write(outputStream);
                        outputStream.close();
                } catch (IOException ex) {
                        flag = false;
                        loger.error(ex);
                } finally {
                        try {
                                workbook.close();
                        } catch (IOException e) {
                        }
                }
                return flag;
        }

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Mime
View raw message