回复 6楼seasky083的帖子
请尝试以下代码,在设置公式前后关闭和开启 EnableCrossSheetReference 属性:
- public ActionResult Index([FarPoint.Mvc.Spread.MvcSpread(true)]FarPoint.Mvc.Spread.FpSpread test)
- {
- test.Sheets.Clear();
- FpSpread book = new FpSpread();
- book.OpenExcel(this.Server.MapPath("test.xlsx"));
- int i = 0;
- test.EnableCrossSheetReference = false;//turn off this flag before open excel
- foreach (FarPoint.Web.Spread.SheetView sheet in book.Sheets)
- {
- FpSpread bookIn = new FpSpread();
- bookIn.Sheets.Add(sheet);
- MemoryStream ms = new MemoryStream();
- bookIn.SaveExcel(ms);
- byte[] b = ms.ToArray();
- FarPoint.Web.Spread.SheetView sv = new FarPoint.Web.Spread.SheetView();
- sv.SheetName = sheet.SheetName;
- test.Sheets.Add(sv);
- sv.OpenExcel(new MemoryStream(b), 0);
- i++;
- }
- test.Sheets[0].Protect = true;
- test.Sheets[0].PageSize = 50;
- test.Width = 1200;
- test.EnableCrossSheetReference = true;
- //test.Sheets[0].SetFormula(1, 0, "需关闭帖子!A1");//值为“模块”
- test.Sheets[0].Cells[1, 0].Formula = "需关闭帖子!A1";
- test.ClientAutoCalculation = true;
- test.Sheets[0].RecalculateAll();
- test.Sheets[1].RecalculateAll();
- test.Sheets[0].AutoCalculation = true;
- test.Sheets[1].AutoCalculation = true;
- return View();
- }
复制代码 |