我的问题与此问题相同,但我不是可以更改Excel文件中的日期格式:
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:
如果我将单元格的格式设置为日期英语(NZ),即日期类型 * 14/03/2001,它会在电子表格中立即显示,但是当我尝试上载它时,日期和月份切换了。但是,如果我将格式更改为自定义的 dd / mm / yyyy格式 [效果很好]。
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].
所以问题是这样的:我可以更改< cfspreadsheet />处理日期格式的方式吗?甚至更好的是,直接从Excel导入中获取Date对象。
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.
编辑:
我找到了解决方案通过使用POI:
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() />使用 getDateCellValue()时,实际日期作为可用的ColdFusion日期。如果< cfspreadsheet /> 本地执行此操作会很好。
When using getDateCellValue() you get the actual date as a usable ColdFusion date back. It would've been nice if <cfspreadsheet /> did this natively.
推荐答案我通过使用POI找到了解决方案:
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() />使用getDateCellValue()时,您会获得实际日期作为可用的ColdFusion日期。如果是本地进行的话,那会很好。
When using getDateCellValue() you get the actual date as a usable ColdFusion date back. It would've been nice if did this natively.
更多推荐
ColdFusion:cfspreadsheet本地化日期格式
发布评论