ASF Bugzilla – Attachment 33149 Details for
Bug 58461
setDefaultColumnStyle() isn't applied to new cells without explicit style (only XSSF)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
Full test case; creates a file first per HSSF, then per XSSF to show the different Excel behaviour
SetDefaultColumnStyleProblem.java (text/x-java), 2.09 KB, created by
Raimund
on 2015-09-26 16:53:22 UTC
(
hide
)
Description:
Full test case; creates a file first per HSSF, then per XSSF to show the different Excel behaviour
Filename:
MIME Type:
Creator:
Raimund
Created:
2015-09-26 16:53:22 UTC
Size:
2.09 KB
patch
obsolete
>package apachepoi; > >import java.io.FileOutputStream; >import java.io.IOException; >import java.io.OutputStream; >import java.util.Calendar; > >import org.apache.poi.hssf.usermodel.HSSFWorkbook; >import org.apache.poi.ss.usermodel.CellStyle; >import org.apache.poi.ss.usermodel.IndexedColors; >import org.apache.poi.ss.usermodel.Row; >import org.apache.poi.ss.usermodel.Sheet; >import org.apache.poi.ss.usermodel.Workbook; >import org.apache.poi.xssf.usermodel.XSSFWorkbook; > >public class SetDefaultColumnStyleProblem { > > public static void main(String[] args) throws IOException { > // HSSF works with MS Excel as OpenOffice as well > testHSSF(); > > // XSSF: data format is missing in MS Excel 2010; OO works > testXSSF(); > } > > static void testHSSF() throws IOException { > Workbook workbook = new HSSFWorkbook(); > Sheet sheet = workbook.createSheet(); > > setDefaultColumnStyle(workbook, sheet); > createOneCell(sheet); > writeToFile(workbook); > > workbook.close(); > } > > static void testXSSF() throws IOException { > Workbook workbook = new XSSFWorkbook(); > Sheet sheet = workbook.createSheet(); > > setDefaultColumnStyle(workbook, sheet); > createOneCell(sheet); > writeToFile(workbook); > > workbook.close(); > } > > static void createOneCell(Sheet sheet) { > // Create one cell; cell contains actual date & time ... > Row row = sheet.createRow(0); > row.createCell(0).setCellValue(Calendar.getInstance()); > } > > static void setDefaultColumnStyle(Workbook workbook, Sheet sheet) { > // Set default column style to format time & yellow background > CellStyle style = workbook.createCellStyle(); > style.setDataFormat(workbook.createDataFormat().getFormat("hh:mm:ss")); > style.setFillForegroundColor(IndexedColors.YELLOW.getIndex()); > style.setFillPattern(CellStyle.SOLID_FOREGROUND); > > sheet.setDefaultColumnStyle(0, style); > } > > static void writeToFile(Workbook workbook) throws IOException { > OutputStream os = new FileOutputStream( > "SetDefaultColumnStyleProblem.xls" > + (workbook instanceof XSSFWorkbook ? "x" : "")); > workbook.write(os); > os.close(); > } > >}
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 58461
: 33149