微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

读取/写入.xlsm文件mvc.net

如何解决读取/写入.xlsm文件mvc.net

嗨,我尝试使用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);

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。