SHARE
TWEET

Untitled

a guest Jun 18th, 2019 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $workbook = PhpOfficePhpSpreadsheetIOFactory::load("modeller.xlsx");
  2.  
  3. $sheet = $workbook->getSheet(1);
  4.  
  5. $c13 = $sheet->getCell('C13')->getValue();
  6. $c43 = $sheet->getCell('C43')->getValue();
  7.  
  8. print_r(['C13 Before calc' => $c13, 'C43 Before calc' => $c43]);
  9.  
  10. $c13 = $sheet->getCell('C13')->setValue(12000);
  11. $c43 = $sheet->getCell('C43')->getCalculatedValue();
  12.  
  13. print_r(['C13 After calc' => $c13, 'C43 After calc' => $c43]);
  14.      
  15. var fi = new FileInfo(@"C:dotnetwebappstestmodeller.xlsx");
  16.  
  17. using (var p = new ExcelPackage(fi))
  18. {
  19.     var ws = p.Workbook.Worksheets["Inputs & Outputs"];
  20.  
  21.     Console.WriteLine("tBefore calc Cell(C13).Value={0}",  ws.Cells["C13"].Value);
  22.     Console.WriteLine("tBefore calc Cell(C43).Value={0}",  ws.Cells["C43"].Value);
  23.  
  24.     ws.Cells["C13"].Value = 12000;
  25.  
  26.     ws.Calculate();
  27.  
  28.     Console.WriteLine("tAfter calc Cell(C13).Value={0}",  ws.Cells["C13"].Value);
  29.     Console.WriteLine("tAfter calc Cell(C43).Value={0}",  ws.Cells["C43"].Value);
  30. }
  31.      
  32. $xl = new COM("Excel.Application");
  33.  
  34. $xl->Visible = false;
  35. $xl->DisplayAlerts = false;
  36.  
  37. $file = 'C:\wamp\www\test\modeller.xlsx';
  38.  
  39. $wb = $xl->Workbooks->Open($file);
  40.  
  41. $ws = $wb->Worksheets('Inputs & Outputs');
  42.  
  43. $c13 = $ws->Range('C12')->Value;
  44. $c43 = $ws->Range('C43')->Value;
  45.  
  46. print_r(['C13 Before calc' => $c13, 'C43 Before calc' => $c43]);
  47.  
  48. $ws->Range('C12')->Value = 12000;
  49.  
  50. $ws->Calculate();
  51.  
  52. $c13 = $ws->Range('C12')->Value;
  53. $c43 = $ws->Range('C43')->Value;
  54.  
  55. print_r(['C13 After calc' => $c13, 'C43 After calc' => $c43]);
  56.  
  57. $wb->Close();
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top