excel - ColdFusion:cfspreadsheet 本地化日期格式

标签 excel date coldfusion coldfusion-9

我的问题与this one基本相同,但我无法更改 Excel 文件中的日期格式:

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].

所以问题是:我可以更改 处理日期格式的方式吗?或者更好的是,直接从 Excel 导入中获取 Date 对象。

编辑:

我通过使用 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 /> 那就太好了本地就这样做了。

最佳答案

我通过使用 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 日期。如果能在本地实现这一点那就太好了。

关于excel - ColdFusion:cfspreadsheet 本地化日期格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19588590/

相关文章:

vba - 仅删除可见行的可见重复项

excel - Excel VBA 中出现 Double 类型溢出错误

date - 如何将日期转换为不同的格式?

php - strtotime() 将一个不存在的日期转换为另一个日期

excel - 使用 xlToLeft 设置范围在第 256 列后失败

mysql - 如何在 Excel 中的 MS Query 中使用临时表?

string - 配置单元转换为日期dd-MM-yyyy

mysql - 如何对 ColdFusion 中循环 Mysql 查询生成的表进行排序?

jquery - Coldfusion 执行存储过程而不刷新页面?

javascript - 在 ColdFusion 中将 Base64 解码为图像