我现在正在使用GemBox Spreadsheet来使用C#读取Excel文件。在Excel文件中,存在包含日期值的单元格,该日期值引用了另一个Excel文件。
首先,在C#中,我得到了零值。基于GemBox Retrieving Calculated Values From a Spreadsheet or Flexcel的帖子,我将Load方法替换为df.set_index('time').resample('H').mean()
。替换后,我得到了一些随机值,例如43257,而不是日期值。我不确定它的价值是什么。
这是代码段:
CREATE SCHEMA vehicle
GO
CREATE TABLE vehicle.sales
(AccountNum VARCHAR(5) NULL,
DealBookDate DATETIME NULL)
INSERT INTO vehicle.sales (AccountNum, DealBookDate) VALUES('R1', '2018-09-18')
INSERT INTO vehicle.sales (AccountNum, DealBookDate) VALUES('R2', '2018-09-18')
INSERT INTO vehicle.sales (AccountNum, DealBookDate) VALUES('R3', '2018-09-18')
INSERT INTO vehicle.sales (AccountNum, DealBookDate) VALUES('R4', '2018-09-18')
INSERT INTO vehicle.sales (AccountNum, DealBookDate) VALUES('R5', '2018-09-18')
INSERT INTO vehicle.sales (AccountNum, DealBookDate) VALUES('R6', '2018-09-18')
INSERT INTO vehicle.sales (AccountNum, DealBookDate) VALUES('R7', '2018-09-18')
INSERT INTO vehicle.sales (AccountNum, DealBookDate) VALUES('R8', '2018-09-18')
INSERT INTO vehicle.sales (AccountNum, DealBookDate) VALUES('R9', '2018-09-18')
INSERT INTO vehicle.sales (AccountNum, DealBookDate) VALUES('R10', '2018-09-18')
INSERT INTO vehicle.sales (AccountNum, DealBookDate) VALUES('R11', '2018-09-18')
INSERT INTO vehicle.sales (AccountNum, DealBookDate) VALUES('R12', '2018-09-18')
INSERT INTO vehicle.sales (AccountNum, DealBookDate) VALUES('R13', '2018-09-18')
INSERT INTO vehicle.sales (AccountNum, DealBookDate) VALUES('R14', '2018-09-18')
INSERT INTO vehicle.sales (AccountNum, DealBookDate) VALUES('R15', '2018-09-18')
SELECT AccountNum
, MONTH(MAX(DealBookDate)) AS mth
, YEAR(MAX(DealBookDate)) AS yr
, DealBookDate
FROM vehicle.sales
WHERE accountnum IN
('R1', 'R2', 'R3', 'R4', 'R5', 'R6', 'R7', 'R8', 'R9', 'R10', 'R11','R12', 'R13', 'R14', 'R15')
GROUP BY AccountNum, DealBookDate
SELECT R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, R13, R14, R15,
mth, yr
FROM
(
SELECT AccountNum
, MONTH(MAX(DealBookDate)) AS mth
, YEAR(MAX(DealBookDate)) AS yr
, DealBookDate
FROM vehicle.sales
WHERE accountnum IN
('R1', 'R2', 'R3', 'R4', 'R5', 'R6', 'R7', 'R8', 'R9', 'R10', 'R11','R12', 'R13', 'R14', 'R15')
GROUP BY AccountNum, DealBookDate
) AS SourceTable
PIVOT
(
COUNT(DealBookDate)
FOR AccountNum
IN (R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, R13, R14, R15)
)
AS PivotTable;
DROP TABLE vehicle.sales
GO
DROP SCHEMA vehicle
GO
我错过了任何设置吗?
答案 0 :(得分:1)
您将以OADate
格式获取日期,数据类型为double
。您必须将其转换回DateTime
格式。
double dateValue = 43257;
DateTime date = DateTime.FromOADate(dateValue);