0
我有一個C#Web窗體應用程序,我想使用Open XML SDK 2.5將gridview的內容導出爲excel。當我在本地主機上運行時,這種工作非常完美,但當我將應用程序移動到UAT網絡服務器時無法正常工作,並且我沒有發生錯誤。我認爲這是一個預備隊的錯誤,但不知道。謝謝,Open SDK無法在Web服務器上運行但在本地主機上運行時打開Excel文件
DocumentFormat.OpenXml.Packaging.SpreadsheetDocument spreadsheet;
DocumentFormat.OpenXml.Spreadsheet.Worksheet worksheet;
System.IO.StreamReader styleXmlReader;
string styleXml;
spreadsheet = Excel.CreateWorkbook(workbookName);
if (spreadsheet == null)
{
return;
}
if (createStylesInCode)
{
Excel.AddBasicStyles(spreadsheet);
}
else
{
using (styleXmlReader = new
System.IO.StreamReader("PredefinedStyles.xml"))
{
styleXml = styleXmlReader.ReadToEnd();
Excel.AddPredefinedStyles(spreadsheet, styleXml);
}
}
Excel.AddSharedString(spreadsheet, "Shared string");
Excel.AddWorksheet(spreadsheet, "Test 1");
Excel.AddWorksheet(spreadsheet, "Test 2");
worksheet =
spreadsheet.WorkbookPart.WorksheetParts.First().Worksheet;
// Headings
Excel.SetCellValue(spreadsheet, worksheet, 1, 1, "QMS Area",
true);
Excel.SetCellValue(spreadsheet, worksheet, 2, 1, "Division
Owner", true);
Excel.SetCellValue(spreadsheet, worksheet, 3, 1, "Relevant
Divisions", true);
Excel.SetCellValue(spreadsheet, worksheet, 4, 1, "Audit Team",
true);
Excel.SetCellValue(spreadsheet, worksheet, 5, 1, "Audit Date",
true);
int _rowCount = 2;
foreach (var audit in _auditDetails)
{
// Set Values
Excel.SetCellValue(spreadsheet, worksheet, 1,
(uint)_rowCount, audit.QmsArea, true);
Excel.SetCellValue(spreadsheet, worksheet, 2,
(uint)_rowCount, audit.DivisionOwner ?? "", true);
Excel.SetCellValue(spreadsheet, worksheet, 3,
(uint)_rowCount, audit.RelevantDivision ?? "", true);
Excel.SetCellValue(spreadsheet, worksheet, 4,
(uint)_rowCount, audit.AuditTeam ?? "", true);
Excel.SetCellValue(spreadsheet, worksheet, 5,
(uint)_rowCount, audit.AuditDate.ToString() ?? "", true);
_rowCount++;
}
// Set column widths
Excel.SetColumnWidth(worksheet, 1, 15);
Excel.SetColumnWidth(worksheet, 2, 20);
worksheet.Save();
spreadsheet.Close();
System.Diagnostics.Process.Start(workbookName);
yes我注意到文件被保存到C:\ Windows \ System32 \ inetsrv中,但我給了該文件夾中的excel文件的完全權限,但它仍然不能正常工作。 – DeadlyDan
您是否完全擁有該文件所在文件夾的權限? – Wellspring