cfspreadsheet本地化日期格式

cfspreadsheet本地化日期格式

本文介绍了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:

所以问题是这样的:我可以更改< 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本地化日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-27 17:17