Hello Everyone i have a problem with my code. when i try to run it i got an error 101590. This is my code where i try to create new excel file and read from a.xml file. I have no idea what am i doing wrong, i have tried to follow instructions that i found on net but it seems like i am missing something. C# :
public HttpResponseMessage PrintDevices()
{
String path = $"{Folder}/{Properties.Settings.Default.Documents_Folder_Template}";
String template = $"{path}/a.xml";
StreamReader sr = File.OpenText(template);
string strSheetData = sr.ReadToEnd();
HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
using (MemoryStream output = new MemoryStream())
{
using (SpreadsheetDocument excelDoc = SpreadsheetDocument.Create(output, DocumentFormat.OpenXml.SpreadsheetDocumentType.Workbook))
{
WorkbookPart workbookPart1 = excelDoc.AddWorkbookPart();
WorksheetPart worksheetPart1 = workbookPart1.AddNewPart<WorksheetPart>();
string sheetId = workbookPart1.GetIdOfPart(worksheetPart1);
string XML = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes""?><workbook xmlns=""http://schemas.openxmlformats.org/spreadsheetml/2006/main"" xmlns:r=""http://schemas.openxmlformats.org/officeDocument/2006/relationships""><sheets><sheet name=""{1}"" sheetId=""1"" r:id=""{0}"" /></sheets></workbook>";
XML = string.Format(XML, sheetId, "Sheet1");
using (Stream stream = workbookPart1.GetStream())
{
byte[] buffer = (new UTF8Encoding()).GetBytes(XML);
stream.Write(buffer, 0, buffer.Length);
}
XML = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes""?><worksheet xmlns=""http://schemas.openxmlformats.org/spreadsheetml/2006/main"" >{0}</worksheet>";
XML = string.Format(XML, strSheetData);
using (Stream stream = worksheetPart1.GetStream())
{
byte[] buffer = (new UTF8Encoding()).GetBytes(XML);
stream.Write(buffer, 0, buffer.Length);
}
excelDoc.Close();
}
}
return response;
}
And this is my xml data inside a.xml:
<?xml version="1.0" encoding="utf-8"?>
<sheetData>
<row r="1">
<c r="A1" t="inlineStr">
<is>
<t>Table</t>
</is>
</c>
<c r="B1" t="inlineStr">
<is>
<t>150</t>
</is>
</c>
<c r="C1" t="inlineStr">
<is>
<t>1</t>
</is>
</c>
</row>
...
...
</sheetData>