// 新規ワークブックの作成 var workbook = new GrapeCity.Documents.Excel.Workbook(); // 最大反復回数と最大変化量を設定 workbook.Options.Formulas.MaximumIterations = 1000; workbook.Options.Formulas.MaximumChange = 0.000001; var activeSheet = workbook.ActiveSheet; activeSheet.Range["A1:A4"].Value = new string[] { "借入金額", "ローン返済期間(月数)", "金利", "支払金額" }; // 借入金額 activeSheet.Range["B1"].Value = 100000; activeSheet.Range["B1"].NumberFormat = @"¥#,##0"; // ローン返済期間(月数) activeSheet.Range["B2"].Value = 180; // 金利 activeSheet.Range["B3"].NumberFormat = "0.00%"; // 支払金額 activeSheet.Range["B4"].Formula = "=PMT(B3/12,B2,B1)"; activeSheet.Range["B4"].NumberFormat = @"¥#,##0"; // ゴールシーク機能を使って、セルB3の値を計算 activeSheet.Range["B4"].GoalSeek(-900, activeSheet.Range["B3"]); activeSheet.Range["A1:B4"].AutoFit(); // xlsx ファイルに保存 workbook.Save("GoalSeek.xlsx");
' 新規ワークブックの作成 Dim workbook As New Workbook ' 最大反復回数と最大変化量を設定 workbook.Options.Formulas.MaximumIterations = 1000 workbook.Options.Formulas.MaximumChange = 0.000001 Dim activeSheet = workbook.ActiveSheet activeSheet.Range("A1:A4").Value = New String() {"借入金額", "ローン返済期間(月数)", "金利", "支払金額"} ' 借入金額 activeSheet.Range("B1").Value = 100000 activeSheet.Range("B1").NumberFormat = "¥#,##0" ' ローン返済期間(月数) activeSheet.Range("B2").Value = 180 ' 金利 activeSheet.Range("B3").NumberFormat = "0.00%" ' 支払金額 activeSheet.Range("B4").Formula = "=PMT(B3/12,B2,B1)" activeSheet.Range("B4").NumberFormat = "¥#,##0" ' ゴールシーク機能を使って、セルB3の値を計算 activeSheet.Range("B4").GoalSeek(-900, activeSheet.Range("B3")) activeSheet.Range("A1:B4").AutoFit() ' xlsx ファイルに保存 workbook.Save("GoalSeek.xlsx")