gpt4 book ai didi

database - 使用 ColdFusion 在 Excel 列中进行文本换行或自动宽度调整

转载 作者:搜寻专家 更新时间:2023-10-30 23:08:18 24 4
gpt4 key购买 nike

我从数据库中提取数据并在 Excel 中为客户呈现。唯一的问题是某些数据对于列来说太大了,并且由于数据是动态的(当然)我基本上需要能够进行一些文本换行或根据需要扩展列的宽度。

我的代码贴在下面

<!---Used for streaming to browser--->
<cfset context = getPageContext()>
<cfset context.setFlushOutput(false)>
<cfset response = context.getResponse().getResponse()>
<cfset out = response.getOutputStream()>
<cfset response.setContentType("application/vnd.ms-excel")>
<cfset response.setHeader("Content-Disposition", "attachment; filename=ERD_Report.xls" )>

<!---Create Workbook and Sheets in workbook--->
<cfset wb = createObject("java","org.apache.poi.hssf.usermodel.HSSFWorkbook").init()/>
<cfset sheet1 = wb.createSheet("ERD Report")/>

<!---Formatting--->
<cfset cellStyleStatic = createObject("java","org.apache.poi.hssf.usermodel.HSSFCellStyle")/>
<cfset cellHSSFFont = createObject("java","org.apache.poi.hssf.usermodel.HSSFFont")/>

<!---Title--->
<cfset fontTitle = wb.createFont()/>
<cfset fontTitle.setFontName("Calibri") />
<cfset fontTitle.setFontHeightInPoints(javacast("int",11))/>
<cfset styleTitle = wb.createCellStyle()/>
<cfset styleTitle.setfont(fontTitle)/>
<cfset styleTitle.setFillPattern(styleTitle.SOLID_FOREGROUND)/>
<cfset styleTitle.setFillForegroundColor(createObject("java","org.apache.poi.hssf.util.HSSFColor$GREY_25_PERCENT").getIndex())/>
<cfset styleTitle.setBorderBottom(styleTitle.BORDER_THIN)/>
<cfset styleTitle.setBorderLeft(styleTitle.BORDER_THIN)/>
<cfset styleTitle.setBorderRight(styleTitle.BORDER_THIN)/>
<cfset styleTitle.setBorderTop(styleTitle.BORDER_THIN)/>

<!---Regular centered white cell with Borders--->
<cfset styleCenter = wb.createCellStyle()/>
<cfset styleCenter.setAlignment(cellStyleStatic.ALIGN_CENTER)/>

<!---Dates--->
<cfset styleDate = wb.createCellStyle()/>
<cfset styleDate.setDataFormat(createObject("java","org.apache.poi.hssf.usermodel.HSSFDataFormat").getBuiltinFormat("m/d/yy"))/>

<!--- Text Wrapping--->
<cfset sheet1.FormatColumn(6, {textwrap="true"})/>

<!---Sheet 1 (Numbers)--->
<!---Rows and columns--->
<cfset row = sheet1.createRow(0)/>
<cfset sheet1.setColumnWidth(0,6000)/>
<cfset sheet1.setColumnWidth(1,6000)/>
<cfset sheet1.setColumnWidth(2,6000)/>
<cfset sheet1.setColumnWidth(3,6000)/>
<cfset sheet1.setColumnWidth(4,6000)/>
<cfset sheet1.setColumnWidth(5,6000)/>
<cfset sheet1.setColumnWidth(6,6000)/>
<cfset sheet1.setColumnWidth(7,6000)/>
<cfset sheet1.setColumnWidth(8,6000)/>
<cfset sheet1.setColumnWidth(9,6000)/>
<cfset sheet1.setColumnWidth(10,6000)/>
<cfset sheet1.setColumnWidth(11,6000)/>
<cfset sheet1.setColumnWidth(12,6000)/>
<cfset sheet1.setColumnWidth(13,6000)/>
<cfset sheet1.setColumnWidth(14,6000)/>
<cfset sheet1.setColumnWidth(15,6000)/>
<cfset sheet1.setColumnWidth(16,6000)/>
<cfset sheet1.setColumnWidth(17,6000)/>
<cfset sheet1.setColumnWidth(18,6000)/>
<cfset cell = row.createCell(0)/>
<cfset cell.setCellValue('Header1')/>
<cfset cell.setCellStyle(styleTitle)/>
<cfset cell = row.createCell(1)/>
<cfset cell.setCellValue('Header2')/>
<cfset cell.setCellStyle(styleTitle)/>
<cfset cell = row.createCell(2)/>
<cfset cell.setCellValue('Header3')/>
<cfset cell.setCellStyle(styleTitle)/>
<cfset cell = row.createCell(3)/>
<cfset cell.setCellValue('Header4')/>
<cfset cell.setCellStyle(styleTitle)/>
<cfset cell = row.createCell(4)/>
<cfset cell.setCellValue('Header5')/>
<cfset cell.setCellStyle(styleTitle)/>
<cfset cell = row.createCell(5)/>
<cfset cell.setCellValue('Header6')/>
<cfset cell.setCellStyle(styleTitle)/>
<cfset cell = row.createCell(6)/>
<cfset cell.setCellValue('Header7')/>
<cfset cell.setCellStyle(styleTitle)/>
<!---<cfset cell = row.createCell(7)/>
<cfset cell.setCellValue('Header8')/>
<cfset cell.setCellStyle(styleTitle)/>--->
<cfset cell = row.createCell(7)/>
<cfset cell.setCellValue('Header9')/>
<cfset cell.setCellStyle(styleTitle)/>
<cfset cell = row.createCell(8)/>
<cfset cell.setCellValue('Header10')/>
<cfset cell.setCellStyle(styleTitle)/>
<cfset cell = row.createCell(9)/>
<cfset cell.setCellValue('Header11')/>
<cfset cell.setCellStyle(styleTitle)/>
<cfset cell = row.createCell(10)/>
<cfset cell.setCellValue('Header12')/>
<cfset cell.setCellStyle(styleTitle)/>
<cfset cell = row.createCell(11)/>
<cfset cell.setCellValue('Header13')/>
<cfset cell.setCellStyle(styleTitle)/>
<cfset cell = row.createCell(12)/>
<cfset cell.setCellValue('Header14')/>
<cfset cell.setCellStyle(styleTitle)/>
<cfset cell = row.createCell(13)/>
<cfset cell.setCellValue('Header15')/>
<cfset cell.setCellStyle(styleTitle)/>
<cfset cell = row.createCell(14)/>
<cfset cell.setCellValue('Header16')/>
<cfset cell.setCellStyle(styleTitle)/>
<cfset cell = row.createCell(15)/>
<cfset cell.setCellValue('Header17')/>
<cfset cell.setCellStyle(styleTitle)/>
<cfset cell = row.createCell(16)/>
<cfset cell.setCellValue('Header18)/>
<cfset cell.setCellStyle(styleTitle)/>
<cfset cell = row.createCell(17)/>
<cfset cell.setCellValue('Header19')/>
<cfset cell.setCellStyle(styleTitle)/>
<cfset cell = row.createCell(18)/>
<cfset cell.setCellValue('Header20')/>
<cfset cell.setCellStyle(styleTitle)/>



<cfloop query="getall">

<!--- Query Engineer Notes for this Tracking Number --->

<cfquery name="Eng_Notes" datasource="#request.dsn#">
SELECT Eng_Notes AS Note
FROM tbl_ERD_Eng_NOTES
WHERE ERD_ID = <cfqueryparam cfsqltype="cf_sql_varchar" value="#getAll.ID#" />
</cfquery>

<cfset variables.lstNotes = valueList(Eng_Notes.Note, " *** ") />

<cfset row = sheet1.createRow(javacast("int",#getall.currentrow#))/>
<cfset cell = row.createCell(0)/>
<cfset cell.setCellValue('#getall.info1#')/>
<cfset cell = row.createCell(1)/>
<cfset cell.setCellValue('#getall.info2#')/>
<cfset cell = row.createCell(2)/>
<cfset cell.setCellValue('#getall.info3#')/>
<cfset cell = row.createCell(3)/>
<cfset cell.setCellValue('#getall.info4#')/>
<cfset cell = row.createCell(4)/>
<cfset cell.setCellValue('#getall.info5#')/>
<cfset cell = row.createCell(5)/>
<cfset cell.setCellValue('#getall.info6#')/>
<cfset cell = row.createCell(6)/>
<cfset cell.setCellValue('#variables.info7#')/>
<!---<cfset cell = row.createCell(7)/>
<cfset cell.setCellValue('#getall.info8#')/>--->
<cfset cell = row.createCell(7)/>
<cfset cell.setCellValue('#getall.info9#')/>
<cfset cell = row.createCell(8)/>
<cfset cell.setCellValue('#getall.info10#')/>
<cfset cell = row.createCell(9)/>
<cfset cell.setCellValue('#getall.info11#')/>
<cfset cell = row.createCell(10)/>
<cfset cell.setCellValue('#getall.info12#')/>
<cfset cell = row.createCell(11)/>
<cfset cell.setCellValue('#getall.info13#')/>
<cfset cell = row.createCell(12)/>
<cfset cell.setCellValue('#getall.info14#')/>
<cfset cell = row.createCell(13)/>
<cfset cell.setCellValue('#getall.info13#')/>
<cfset cell = row.createCell(14)/>
<cfset cell.setCellValue('#getall.info14#')/>
<cfset cell = row.createCell(15)/>
<cfset cell.setCellValue('#getall.info15#')/>
<cfset cell = row.createCell(16)/>
<cfset cell.setCellValue('#getall.info16#')/>
<cfset cell = row.createCell(17)/>
<cfset cell.setCellValue('#getall.info17#')/>
<cfset cell = row.createCell(18)/>
<cfset cell.setCellValue('#getall.info18#')/>
</cfloop>

我尝试使用 SpreadsheetFormatCellas posted here ,虽然我知道它只会文本换行 1 个单元格。所完成的只是让我的 Excel 页面显示 HTTP 500 页面。

我也试过 SpreadsheetFormatColumn 方法,as posted here , 并且有很多错误。

任何帮助都会很棒,如果有另一篇与这篇文章类似的文章,请指出我的方向。我总是有可能错过它。

最佳答案

使用 ColdFusion 9,对吧?这令人沮丧,因为 ColdFusion 9 文档声明它可以工作,但它被严重破坏了。我认为这可能已在最近的 ColdFusion 11 中得到修复,但它仍然使用多个旧版本的 Apache POI 库。

尝试使用 spreadsheetWrite()。我发现使用标签与脚本保存时存在差异:

http://gamesover2600.tumblr.com/post/65341875453/differences-saving-coldfusion-excel-data-w-tag-vs

注意:如果可以使用 CFLive.net 或 TryCF.com 完成此类测试,那就太好了,但出于安全原因,它们不允许生成文件。

关于database - 使用 ColdFusion 在 Excel 列中进行文本换行或自动宽度调整,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23477840/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com