Bug 60838 - Office 2013 AP after column style will be lost
Summary: Office 2013 AP after column style will be lost
Status: NEEDINFO
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 3.12-FINAL
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-03-09 02:44 UTC by liupengzhu
Modified: 2017-03-18 19:15 UTC (History)
0 users



Attachments
example (7.00 KB, application/vnd.ms-excel)
2017-03-09 02:44 UTC, liupengzhu
Details

Note You need to log in before you can comment on or make changes to this bug.
Description liupengzhu 2017-03-09 02:44:07 UTC
Created attachment 34809 [details]
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;
	}
Comment 1 Dominik Stadler 2017-03-18 19:15:20 UTC
There were many fixes in newer versions, maybe this one is already solved. Can you verify with the latest, preferably 3.16-beta2 to check if it still happens in the latest version?