【发布时间】:2018-10-31 05:53:41
【问题描述】:
我正在将 excel 文件导入哈希表,然后将哈希表作为 WebServiceResponse 响应的一部分传递到前端以进行显示。某些文件的数据显示,但对于我尝试导入的某些文件,日期显示为 /日期(1453154400000)/.
正在寻找一种将这种格式转换为 DD/MM/YYYY 日期格式的方法
public WebServiceResponse ReadFile(string fileName, string inputFormat)
{
string filePath = Server.MapPath("~/upload/");
string filePath = Server.MapPath("~/upload/");
string strConnection =
string.Format(
"Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source={0}{1};"
+ "Extended Properties=\"Excel
12.0;HDR=NO;IMEX=1;ImportMixedTypes=Text;\"", filePath, fileName);
var jsonArray = new List<Hashtable>();
string.
using (var cnConnection = new OleDbConnection(strConnection))
{
cnConnection.Open();
try
{
var cmdSelectSections = new
OleDbCommand(string.Format("SELECT * FROM [{0}]", "Sheet1$"),
cnConnection);
OleDbDataReader drdSections =
cmdSelectSections.ExecuteReader();
// Import excel rows into XML files
if (drdSections != null)
{
while (drdSections.Read())
{
var record = new Hashtable();
for (int j = 0; j < drdSections.FieldCount; j++)
{
record.Add("Col" + j.ToString(CultureInfo.InvariantCulture),
drdSections[j]);
}
jsonArray.Add(record);
//}
}
}
}
finally
{
cnConnection.Close();
}
}
var coldef = new string[20];
var numberOfCols = jsonArray[0].Count;
var i = 0;
var result = new Hashtable
{
{"colDef", coldef},
{"data", jsonArray}
};
return WebServiceResponse.PassResponse(result);
}
【问题讨论】:
-
1234656000000代表什么日期? -
/Date(1453154400000)/ 在电子表格上是 01/19/2016
-
是 1453154400000 long int 值吗?
-
@Prince 该文本来自哪里?
/Date(1453154400000)/是微软在没有关于 JSON 日期的约定时引入的非常古老且废弃的 JSON 日期格式。您的服务是否返回该文本或 Excel 是否包含该文本?WebServiceResponse是什么,PassResponse有什么作用?