ColdFusion:cfspreadsheet本地化日期格式

编程入门 行业动态 更新时间:2024-10-24 21:29:29
本文介绍了ColdFusion:cfspreadsheet本地化日期格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的问题与此问题相同,但我不是可以更改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本地化日期格式

本文发布于:2023-10-23 00:05:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1519141.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:日期   格式   ColdFusion   cfspreadsheet

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!