ASF Bugzilla – Attachment 26865 Details for
Bug 51037
setDefaultColumnStyle() in XSSFSheet not working
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
Full test class
VariousSS.java (text/x-java-source), 2.16 KB, created by
M8R-3mye921
on 2011-04-07 05:20:24 UTC
(
hide
)
Description:
Full test class
Filename:
MIME Type:
Creator:
M8R-3mye921
Created:
2011-04-07 05:20:24 UTC
Size:
2.16 KB
patch
obsolete
>package test.poi; > >import java.io.BufferedOutputStream; >import java.io.File; >import java.io.FileOutputStream; >import java.io.IOException; > >import org.apache.poi.hssf.usermodel.HSSFWorkbook; >import org.apache.poi.ss.usermodel.Cell; >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 VariousSS { > private static final File OUTPUT_FOLDER = new File("output/"); > > public static Cell get(Row r, int columnIndex) { > Cell c = r.getCell(columnIndex); > return (c != null) ? c : r.createCell(columnIndex); > } > > public static void fill(Row r, String ... contents) { > for (int i = 0; i < contents.length; i++) { > get(r, i).setCellValue(contents[i]); > } > } > > public static void save(Workbook wb, String fileName) throws IOException { > BufferedOutputStream stream = new BufferedOutputStream(new FileOutputStream(new File(OUTPUT_FOLDER, fileName))); > wb.write(stream); > stream.close(); > } > > public static void columnStyles(boolean xml) throws IOException { > Workbook wb = xml ? new XSSFWorkbook() : new HSSFWorkbook(); > > CellStyle blueStyle = wb.createCellStyle(); > blueStyle.setFillForegroundColor(IndexedColors.AQUA.getIndex()); > blueStyle.setFillPattern(CellStyle.SOLID_FOREGROUND); > > CellStyle pinkStyle = wb.createCellStyle(); > pinkStyle.setFillForegroundColor(IndexedColors.PINK.getIndex()); > pinkStyle.setFillPattern(CellStyle.SOLID_FOREGROUND); > > Sheet s1 = wb.createSheet("Pretty columns"); > > s1.setDefaultColumnStyle(4, blueStyle); > s1.setDefaultColumnStyle(6, pinkStyle); > > Row r = s1.createRow(7); > r.createCell(1).setCellStyle(pinkStyle); > r.createCell(8).setCellStyle(blueStyle); > > fill(s1.createRow(3), "The quick brown fox jumps over the lazy dog".split("\\s+")); > save(wb, (xml ? "columnStyles.xlsx" : "columnStyles.xls")); > } > > public static void main(String[] args) { > try { > columnStyles(true); > } catch (Exception 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 51037
: 26865