SpreadsheetDocument.Create() returns 不支持 URI 格式

SpreadsheetDocument.Create() returns URI formats are not supported

我正在使用 C# 代码为我组织的本地服务器创建一个文件 (Excel)。

当我在服务器 IP 前添加“http”时,我总是收到错误“URI formats are not supported”。 如果我自动删除“http”,则会添加“C://”,这会导致找不到路径错误。

任何人都可以建议一种正确格式化 URL 的方法吗?

  string uriPath = "http:\1.1.1.1\Test\Reports-IdH-ls\Reports\tes.xlsx";

  ExportDSToExcel(DatasetItem, uriPath);

  ...
  private void ExportDSToExcel(DataSet ds, string destination)
  {
      using (var workbook = SpreadsheetDocument.Create(destination, DocumentFormat.OpenXml.SpreadsheetDocumentType.Workbook))
      {
          var workbookPart = workbook.AddWorkbookPart();
          workbook.WorkbookPart.Workbook = new DocumentFormat.OpenXml.Spreadsheet.Workbook();
          workbook.WorkbookPart.Workbook.Sheets = new DocumentFormat.OpenXml.Spreadsheet.Sheets();

          uint sheetId = 1;

          foreach (DataTable table in ds.Tables)
          {
              // fill table ...
          }
      }
  }

你能试试下面的方法吗?

string uriPath = "\\1.1.1.1\Test\Reports-IdH-ls\Reports\tes.xlsx";

在 C# 中,如果需要反斜杠,则需要添加另一个反斜杠对其进行转义,使其成为文字反斜杠。