//create a new workbook var workbook = new GrapeCity.Documents.Excel.Workbook(); //Set MaximumIterations and MaximumChange workbook.Options.Formulas.MaximumIterations = 1000; workbook.Options.Formulas.MaximumChange = 0.000001; var activeSheet = workbook.ActiveSheet; activeSheet.Range["A1:A4"].Value = new string[] { "Loan Amount", "Term in Months", "Interest Rate", "Payment" }; // This is the amount that you want to borrow. activeSheet.Range["B1"].Value = 100000; activeSheet.Range["B1"].NumberFormat = "$#,##0"; // This is the number of months that you want to pay off the loan. activeSheet.Range["B2"].Value = 180; // This is the number of interest rate. activeSheet.Range["B3"].NumberFormat = "0.00%"; // This formula calculates the payment amount. activeSheet.Range["B4"].Formula = "=PMT(B3/12,B2,B1)"; activeSheet.Range["B4"].NumberFormat = "$#,##0"; // Use goal seek to calculate the value of cell B3. activeSheet.Range["B4"].GoalSeek(-900, activeSheet.Range["B3"]); activeSheet.Range["A1:B4"].AutoFit(); // Save to an excel file workbook.Save("GoalSeek.xlsx");
' Create a new Workbook Dim workbook As New Workbook ' Set MaximumIterations And MaximumChange workbook.Options.Formulas.MaximumIterations = 1000 workbook.Options.Formulas.MaximumChange = 0.000001 Dim activeSheet = workbook.ActiveSheet activeSheet.Range("A1:A4").Value = New String() {"Loan Amount", "Term in Months", "Interest Rate", "Payment"} ' This is the amount that you want to borrow. activeSheet.Range("B1").Value = 100000 activeSheet.Range("B1").NumberFormat = "$#,##0" ' This is the number of months that you want to pay off the loan. activeSheet.Range("B2").Value = 180 ' This is the number of interest rate. activeSheet.Range("B3").NumberFormat = "0.00%" ' This formula calculates the payment amount. activeSheet.Range("B4").Formula = "=PMT(B3/12,B2,B1)" activeSheet.Range("B4").NumberFormat = "$#,##0" ' Use goal seek to calculate the value of cell B3. activeSheet.Range("B4").GoalSeek(-900, activeSheet.Range("B3")) activeSheet.Range("A1:B4").AutoFit() ' save to an excel file workbook.Save("GoalSeek.xlsx")