OleDBConn没有采用最新的Excel文件

时间:2015-06-01 14:46:19

标签: c# oledbconnection navision

我正在下载XLS格式的Excel,我从银行链接获取并保存到系统中的特定路径。从那里我使用OleDBConnection Automation将XLS导入我的表。

主要的两个功能如下所示。

SaveExcelFile()
MYURL := 'https://www.commerzbank.hu/portal/media/corporatebanking/auslandsseiten/ungarn-informationen/englisch-/kursinformationen/deviza_noon.xls';

IF ISCLEAR(WinHTTP) THEN
  CREATE(WinHTTP,TRUE,TRUE);

WinHTTP.open('GET',MYURL,FALSE);
WinHTTP.send('');

IF WinHTTP.status <> 200 THEN
  ERROR(Text023,WinHTTP.status,WinHTTP.statusText);

FileName := 'file.xls';
IF ISCLEAR(ADOStream) THEN
  CREATE(ADOStream,TRUE,TRUE);

IF ADOStream.State = 1 THEN
  ADOStream.Close;

ADOStream.Type := 1; // adVarBinary
ADOStream.Open;
ADOStream.Write(WinHTTP.responseBody);

IF ISCLEAR(FileSystem) THEN
  CREATE(FileSystem,TRUE,TRUE);

//FileFolder := FileSystem.GetSpecialFolder(2);
//FilePath := FileFolder.Path;
FilePath := 'C:\Temp';
ADOStream.SaveToFile(FilePath + '\' + FileName,2);
FileName := FilePath + '\' + FileName;
//MESSAGE('%1',FileName);
ADOStream.Close;
ImportExcel(FileName);



ImportExcel(FileName : Text)
DateField :=TRUE;
OleDBConn := OleDBConn.OleDbConnection('Provider=Microsoft.ACE.OLEDB.12.0;Data Source='+ FileName + ';Extended Properties="Excel 12.0;HDR=No;IMEX=1"');
SheetName := 'Deviza';
OleDBConn.Open();

OleDBCmd := OleDBCmd.OleDbCommand('select * from [' + SheetName + '$A4:D25]',OleDBConn);
OleDBCmd.Parameters.Clear();
OleDBReader := OleDBCmd.ExecuteReader();

"UploadCurrencyExch.Rate2".SETCURRENTKEY("UploadCurrencyExch.Rate2"."Entry No.");
IF "UploadCurrencyExch.Rate2".FINDLAST THEN
  "EntryNo." := "UploadCurrencyExch.Rate2"."Entry No.";

WHILE OleDBReader.Read() DO BEGIN
  IF FORMAT(OleDBReader.GetValue(0)) <> 'null' THEN BEGIN
    "UploadCurrencyExch.Rate2".INIT;
    IF DateField = TRUE THEN BEGIN
      EVALUATE(UploadDate,FORMAT(OleDBReader.GetValue(0)));
      DetectDuplicateCurrencyUpload(UploadDate);
      EVALUATE("UploadCurrencyExch.Rate2"."Upload Date",FORMAT(OleDBReader.GetValue(0)));
      //"UploadCurrencyExch.Rate2"."Upload Date" := TODAY;
      "UploadCurrencyExch.Rate2".Status := "UploadCurrencyExch.Rate2".Status::Open;
      "UploadCurrencyExch.Rate2"."Exchange Status" := "UploadCurrencyExch.Rate2"."Exchange Status"::Noon;
      "UploadCurrencyExch.Rate2"."Entry No." := "EntryNo."+1;
      CLEAR("UploadCurrencyExch.Rate2"."Currency Code");
      "EntryNo." := "EntryNo."+1;
    END ELSE BEGIN
      EVALUATE("UploadCurrencyExch.Rate2"."Upload Date",UploadDate);
      //"UploadCurrencyExch.Rate2"."Upload Date" := TODAY;
      IF FORMAT(OleDBReader.GetValue(0)) <> 'null' THEN
        "UploadCurrencyExch.Rate2"."Currency Code" := FORMAT((OleDBReader.GetValue(0)));
      IF FORMAT(OleDBReader.GetValue(1)) <> 'null' THEN
        EVALUATE("UploadCurrencyExch.Rate2"."Buying Rate",FORMAT(OleDBReader.GetValue(1)));
      IF FORMAT(OleDBReader.GetValue(2)) <> 'null' THEN
        EVALUATE("UploadCurrencyExch.Rate2"."Agent Rate",FORMAT(OleDBReader.GetValue(2)));
      IF FORMAT(OleDBReader.GetValue(3)) <> 'null' THEN
        EVALUATE("UploadCurrencyExch.Rate2"."Sales Rate",FORMAT(OleDBReader.GetValue(3)));
      "UploadCurrencyExch.Rate2".Status := "UploadCurrencyExch.Rate2".Status::Open;
      "UploadCurrencyExch.Rate2"."Exchange Status" := "UploadCurrencyExch.Rate2"."Exchange Status"::Noon;
      "UploadCurrencyExch.Rate2"."Entry No." := "EntryNo."+1;
      "EntryNo." := "EntryNo."+1;
    END;
    "UploadCurrencyExch.Rate2".INSERT;
    DateField := FALSE;
   END;
END;
OleDBReader.Close();
OleDBCmd.Parameters.Clear();
OleDBConn.Close();
OleDBConn.ReleaseObjectPool();

每件事都很好。但我遇到的问题是插入的Excel数据不是最新的。它始终取自先前导入的Excel文件。

让我感到困惑的是,旧的Excel罚款在系统中根本不可用,因为它被新的替换。我已通过手动打开XLS文件确认了这一点。

Excel文件不是从任何其他地方获取的,我已经通过保持Excel文件打开来尝试执行该功能来确认它,这将通过我一个错误。

我认为数据没有从缓存中清除。不知道如何清除它。请帮帮我们。

0 个答案:

没有答案