我Apache POI API用来生成excel spreadsheet输出一些数据.
我面临的问题是,在创建和打开电子表格时,不会扩展列,以便乍一看不会出现像Date格式化文本这样的长文本.
我可以双击excel中的列边框来展开或拖动边框来调整列宽,但可能有20多列,每次打开电子表格时我都无法手动执行此操作:(
我发现了(虽然可能是错误的方法)groupRow()并且setColumnGroupCollapsed()可能能够做到这一点,但没有运气.也许我错误地使用它.
示例代码段
Workbook wb = new HSSFWorkbook();
CreationHelper createHelper = wb.getCreationHelper();
//create sheet
Sheet sheet = wb.createSheet("masatoSheet");
//not really working yet.... :(
//set group for expand/collapse
//sheet.groupRow(0, 10); //just random fromRow toRow argument values...
//sheet.setColumnGroupCollapsed(0, true);
//create row
Row row = sheet.createRow((short)0);
//put a cell in the row and store long text data
row.createCell(0).setCellValue("Loooooooong text not to show up first");
Run Code Online (Sandbox Code Playgroud)
创建此电子表格时,"Looooooong text not to first up …
我正在使用Apache POI API编写一个Java工具,将XML转换为MS Excel.在我的XML输入中,我以磅为单位接收列宽.但Apache POI API有一个稍微奇怪的逻辑,用于根据字体大小等设置列宽(请参阅API文档)
是否存在将点转换为Excel预期宽度的公式?有没有人这样做过?
setRowHeightInPoints()虽然有一种方法:(但没有列.
PS:输入XML是ExcelML格式,我必须转换为MS Excel.
如何在Apache POI中设置固定列宽.我想让我的第一列固定宽度.
我试过了sheet.setColumnWidth(0,1000); cellStyle.setWrapText(真); //设置wordwrap它没有反映
public XSSFWorkbook generateReport(List<Dto> result, boolean isRes, boolean isRes1) {
XSSFWorkbook workbook = null;
XSSFSheet sheet = null;
XSSFRow row = null;
XSSFCell cell = null;
String[] headers = null;
int rowNum = 0;
int colNum = 0;
CellStyle cellStyle = null;
CellStyle headerStyle = null;
XSSFFont font = null;
CellStyle datecellStyle = null;
/* set the weight of the font */
try {
workbook = new XSSFWorkbook();
headers = new String[] { ...values goes here...}; …Run Code Online (Sandbox Code Playgroud)