[英]SpreadsheetDocument.Create() returns URI formats are not supported
I am creating a file (Excel) using C# code to a local server in my organisation. 我正在使用C#代码向组织中的本地服务器创建文件(Excel)。
I keep getting the error " URI formats are not supported
" when I add " http
" before the IP of the server. 当在服务器IP之前添加“ http
”时,我不断收到错误消息“ URI formats are not supported
”。 If I remove the " http
" automatically " C://
" is added which result in path not found error. 如果我自动删除了“ http
”,则会添加“ C://
”,从而导致找不到路径错误。
Can anybody suggest a way to properly format the URL? 有人可以建议一种正确格式化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 ...
}
}
}
Can you try the following? 您可以尝试以下吗?
string uriPath = "\\\\1.1.1.1\\Test\\Reports-IdH-ls\\Reports\\tes.xlsx";
In C#, if you want a backslash, you need to add another backslash to escape it to make it a literal backslash. 在C#中,如果要使用反斜杠,则需要添加另一个反斜杠以对其进行转义以使其成为文字反斜杠。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.