ColdFusion: cfspreadsheet localized date format

≯℡__Kan透↙ 提交于 2020-06-14 07:56:05

问题


My question is basically the same as this one, but I'm not in a position to change the date format in the Excel file:

If I format the cell as date english (NZ), ie Date Type "*14/03/2001", it displays right in the spreadsheet, but when I try to upload it switched the day and month. But If I change the format to a custom "dd/mm/yyyy" format [it works fine].

So the question is this: Can I change the way <cfspreadsheet /> handles date formats? Or even better, get a Date object directly from the Excel import.

EDIT:

I found a solution by using POI:

<cfset fileIS = createObject( "java", "java.io.FileInputStream" ).init( "#request.site.sImportPath#\#variables.file#" ) />
<cfset excelFS = createObject( "java", "org.apache.poi.poifs.filesystem.POIFSFileSystem" ).init( fileIS ) />
<cfset workBook = CreateObject( "java", "org.apache.poi.hssf.usermodel.HSSFWorkbook" ).init( excelFS ) />
<cfset sheet = workBook.getSheet( "mySheetName" ) />

<cfset myDateValue = sheet.getRow( 20 ).getCell( 2 ).getDateCellValue() />

When using getDateCellValue() you get the actual date as a usable ColdFusion date back. It would've been nice if <cfspreadsheet /> did this natively.


回答1:


I found a solution by using POI:

<cfset fileIS = createObject( "java", "java.io.FileInputStream" ).init( "#request.site.sImportPath#\#variables.file#" ) />
<cfset excelFS = createObject( "java", "org.apache.poi.poifs.filesystem.POIFSFileSystem" ).init( fileIS ) />
<cfset workBook = CreateObject( "java", "org.apache.poi.hssf.usermodel.HSSFWorkbook" ).init( excelFS ) />
<cfset sheet = workBook.getSheet( "mySheetName" ) />

<cfset myDateValue = sheet.getRow( 20 ).getCell( 2 ).getDateCellValue() />

When using getDateCellValue() you get the actual date as a usable ColdFusion date back. It would've been nice if did this natively.



来源:https://stackoverflow.com/questions/19588590/coldfusion-cfspreadsheet-localized-date-format

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!