Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 读/写.xlsm文件mvc.net_Asp.net Mvc_Xlsm - Fatal编程技术网

Asp.net mvc 读/写.xlsm文件mvc.net

Asp.net mvc 读/写.xlsm文件mvc.net,asp.net-mvc,xlsm,Asp.net Mvc,Xlsm,嗨,我尝试使用Excel文件和C#。当我尝试写入和上载时,文件被损坏,我无法打开上载的文件。如果你能帮忙,谢谢 XLWorkbook wb = new XLWorkbook(Server.MapPath("~/Areas/Credit/App/Files/Book1.xlsm")) { Author = "AAICCo" }; var ws = wb.Worksheet("Main");

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