嗨,我尝试使用Excel文件和C#。尝试写入并上传时,文件已损坏,无法打开上传的文件。如果可以的话,谢谢
XLWorkbook wb = new XLWorkbook(Server.MapPath("~/Areas/Credit/App/Files/Book1.xlsm")) { Author = "AAICCo" };
var ws = wb.Worksheet("Main");
var model = _caseBusiness.GetRatingExcelReport(caseRateDateId);
int count = 9;
foreach (var item in model)
{
wb.Worksheet("Main").Cell(count, 1).Value = item.BaseTitle;
wb.Worksheet("Main").Cell(count, 2).Value = item.TypeTitle;
wb.Worksheet("Main").Cell(count, 3).Value = item.Title;
wb.Worksheet("Main").Cell(count, 4).Value = item.Code;
wb.Worksheet("Main").Cell(count, 5).Value = item.Id;
wb.Worksheet("Main").Cell(count, 6).Value = item.CaseRateDateId;
wb.Worksheet("Main").Cell(count, 7).Value = item.RawValueDecimal != null ? item.RawValueDecimal.ToString() : item.RawValueInput;
wb.Worksheet("Main").Cell(count, 8).Value = item.Result;
wb.Worksheet("Main").Cell(count, 9).Value = item.MaxScore;
wb.Worksheet("Main").Cell(count, 10).Value = item.TrendIndex;
wb.Worksheet("Main").Cell(count, 11).Value = item.SUMMultiplierQuestion;
wb.Worksheet("Main").Cell(count, 12).Value = item.Weight;
wb.Worksheet("Main").Cell(count, 13).Value = item.ThresholdScore;
count++;
}
//var table = wb.Worksheets.Worksheet("Main").Tables.ToList();
var base64Data = "";
using (MemoryStream stream = new MemoryStream())
{
wb.SaveAs(stream);
base64Data = Convert.ToBase64String(stream.ToArray());
}
wb.Dispose();
//return wb.Deliver("NewRating_ExcelReport" + DateTimeUtility.ToClientDateByCulture(DateTime.Now) + ".xlsm");
return jsonModel(base64Data);