这是到目前为止我的代码,它从一个查询获取数据然后将其导出到Excel文档:Excel单元格的格式 - XSSF工作簿
<cfscript>
oArray = CreateObject("java", "java.util.Arrays");
workbook = CreateObject("java", "org.apache.poi.xssf.usermodel.XSSFWorkbook");
workbook.init();
myFont = workbook.createFont();
myFont.setBoldweight(myFont.BOLDWEIGHT_BOLD);
boldStyle = workbook.createCellStyle();
boldStyle.setFont(myFont);
</cfscript>
<!--- Set up the headings for the Excel worksheet --->
<cfscript>
thisSheet = workbook.createSheet(JavaCast("string", 'invoices due'));
rows = {};
// we need to refer to these three rows later on
rows[1] = thisSheet.createRow(0);
rows[2] = thisSheet.createRow(1);
rows[3] = thisSheet.createRow(2);
rows[4] = thisSheet.createRow(3);
//Report parameters explanation
thisCell = rows[2].createCell(0, 1);
thisCell.setCellValue(reportSum);
// user column headings
thisCell = rows[4].createCell(0, 1);
thisCell.setCellValue('Value');
thisCell.setCellStyle(boldStyle);
thisCell = rows[4].createCell(1, 1);
thisCell.setCellValue('Team');
thisCell.setCellStyle(boldStyle);
thisCell = rows[4].createCell(2, 1);
thisCell.setCellValue('Manager');
thisCell.setCellStyle(boldStyle);
</cfscript>
<cfset row = 5>
<cfloop query="invoicesDue">
<cfscript>
thisRow = thisSheet.createRow(JavaCast("int", row));
thisCell = thisRow.createCell(0, 1);
thisCell.setCellValue(HTMLEditFormat(invoicesDue.value));
thisCell = thisRow.createCell(1, 1);
thisCell.setCellValue(HTMLEditFormat(invoicesDue.ct_team));
thisCell = thisRow.createCell(2, 1);
thisCell.setCellValue(HTMLEditFormat(invoicesDue.manager));
thisCell = thisRow.createCell(3, 1);
</cfscript>
</cfloop>
<cfscript>
// todo: change to datadir from getAppRoot
outputFileName = "invoicesDue(withfundingsource)" & "_" & RandRange(00000,99999) & ".xlsx";
fos = CreateObject("java", "java.io.FileOutputStream");
fos.init(outputFilename);
workbook.write(fos);
fos.close();
</cfscript>
我所试图做的是格式化为列标题为“价值”Excel数据格式“会计”。我已经做了研究,但我很困难。
任何想法?
有你看着给SXXFDataFormat,https://poi.apache.org/apidocs/org/apache /poi/xssf/usermodel/XSSFDataFormat.html这个例子使用HSSF,但应该与SXXFDataFormat相同或非常相似,都使用DataFormat接口http://npoi.codeplex.com/discussions/391336 – Travis
@Travis - 我不知道关于.net端口,但在Java版本中,'Accounting'是内置格式之一,即'44'。 (如果你转储他们,大多数的Excel标准都在那里) – Leigh
我在vba中看到了几个,没有看到它在java ID中。老实说,从来没有用过poi,只是我在一些快速研究中能找到的东西。 – Travis