// 新規ワークブックの作成 var workbook = new GrapeCity.Documents.Excel.Workbook(); object[,] data = new object[,]{ {"Name", "City", "Birthday", "Eye color", "Weight", "Height"}, {"Richard", "New York", new DateTime(1968, 6, 8), "Blue", 67, 165}, {"Nia", "New York", new DateTime(1972, 7, 3), "Brown", 62, 134}, {"Jared", "New York", new DateTime(1964, 3, 2), "Hazel", 72, 180}, {"Natalie", "Washington", new DateTime(1972, 8, 8), "Blue", 66, 163}, {"Damon", "Washington", new DateTime(1986, 2, 2), "Hazel", 76, 176}, {"Angela", "Washington", new DateTime(1993, 2, 15), "Brown", 68, 145} }; IWorksheet worksheet = workbook.Worksheets[0]; worksheet.Range["A1:F7"].Value = data; worksheet.Range["A:F"].ColumnWidth = 15; // テーブルを追加 worksheet.Tables.Add(worksheet.Range["A1:F7"], true); // 集計行(平均)を表示 worksheet.Tables[0].ShowTotals = true; worksheet.Tables[0].Columns[4].TotalsCalculation = TotalsCalculation.Average; worksheet.Tables[0].Columns[5].TotalsCalculation = TotalsCalculation.Average; var comment = worksheet.Range["F8"].AddComment("F9 を押して再計算してください。"); comment.Visible = true; // 計算モードをManualに設定 workbook.Options.Formulas.CalculationMode = CalculationMode.Manual; // xlsx ファイルに保存 workbook.Save("CalculationOptions.xlsx");
' 新規ワークブックの作成 Dim workbook As New Workbook Dim data(,) As Object = { {"Name", "City", "Birthday", "Eye color", "Weight", "Height"}, {"Richard", "New York", New DateTime(1968, 6, 8), "Blue", 67, 165}, {"Nia", "New York", New DateTime(1972, 7, 3), "Brown", 62, 134}, {"Jared", "New York", New DateTime(1964, 3, 2), "Hazel", 72, 180}, {"Natalie", "Washington", New DateTime(1972, 8, 8), "Blue", 66, 163}, {"Damon", "Washington", New DateTime(1986, 2, 2), "Hazel", 76, 176}, {"Angela", "Washington", New DateTime(1993, 2, 15), "Brown", 68, 145} } Dim worksheet As IWorksheet = workbook.Worksheets(0) worksheet.Range("A1:F7").Value = data worksheet.Range("A:F").ColumnWidth = 15 ' テーブルを追加 worksheet.Tables.Add(worksheet.Range("A1:F7"), True) ' 集計行(平均)を表示 worksheet.Tables(0).ShowTotals = True worksheet.Tables(0).Columns(4).TotalsCalculation = TotalsCalculation.Average worksheet.Tables(0).Columns(5).TotalsCalculation = TotalsCalculation.Average Dim comment = worksheet.Range("F8").AddComment("F9 を押して再計算してください。") comment.Visible = True ' 計算モードをManualに設定 workbook.Options.Formulas.CalculationMode = CalculationMode.Manual ' xlsx ファイルに保存 workbook.Save("CalculationOptions.xlsx")