本文介绍了将xls文件加载到SpreadSheetGear工作簿时如何设置默认日期格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我将由用户创建的xls文件加载到SpreadSheetGear工作簿时,将日期格式从dd / mm / yyyy更改为mm / dd / yyyy。我如何防止这种情况?

When I load an xls file, which is created by the user, to SpreadSheetGear workbook it changes date format from dd/mm/yyyy to mm/dd/yyyy. How can I prevent this?

我使用下面的代码(VB.NET)加载xls文件:

I use the code below (VB.NET) to load xls file:

WorkbookView1.ActiveWorkbook =  
    SpreadsheetGear.Factory.GetWorkbookSet.Workbooks.OpenFromMemory(xlsFile)

xlsFile是一个字节数组。

xlsFile is a Byte array.

推荐答案

在将excel xlsx导入到我的尽管系统数据设置为dd / MM / yyyy,但是将日期从dd / MM / yyyy转换为MM / dd / yyyy,下面的方法给了我正确的格式。

I had the problem when importing excel xlsx to my site it was shifting the date from dd/MM/yyyy to MM/dd/yyyy though the system data was set to dd/MM/yyyy, the below method gave me the correct format I want.

 Dim dsFromExcel As DataSet = New DataSet
 Dim mywb As SpreadsheetGear.IWorkbook = SpreadsheetGear.Factory.GetWorkbook(strFileName)
 Dim myws As SpreadsheetGear.IWorksheet = mywb.Sheets(0)
 Dim Myrange As SpreadsheetGear.IRange = myws.Cells

'this will set the format of the first column A to this date format
 Myrange("A:A").NumberFormat = "MM/dd/yyyy HH:mm:ss"

'importing the data to a dataset/datatable
 dsFromExcel = mywb.GetDataSet(SpreadsheetGear.Data.GetDataFlags.FormattedText)

Dim dt As DataTable = New DataTable
dt = dsFromExcel.Tables(0)

这篇关于将xls文件加载到SpreadSheetGear工作簿时如何设置默认日期格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 02:06