[英]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#中,如果要使用反斜杠,則需要添加另一個反斜杠以對其進行轉義以使其成為文字反斜杠。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.