// 新規ワークブックの作成 var workbook = new GrapeCity.Documents.Excel.Workbook(); #region カスタムクラスの定義 //public class SalesRecord //{ // public string Area; // public string City; // public string Category; // public string Name; // public double Revenue; //} #endregion #region データの初期化 var record = new SalesRecord { Area = "北米", City = "シカゴ", Category = "家電製品", Name = "Bose 785593-0050", Revenue = 92800 }; #endregion IWorksheet worksheet = workbook.Worksheets[0]; // セルにバインディングパスを設定 worksheet.Range["A1"].BindingPath = "Area"; worksheet.Range["B2"].BindingPath = "City"; worksheet.Range["C2"].BindingPath = "Name"; worksheet.Range["D3"].BindingPath = "Revenue"; // データソースを設定 worksheet.DataSource = record; // xlsx ファイルに保存 workbook.Save("CellBinding.xlsx");
' 新規ワークブックの作成 Dim workbook As New Workbook #Region "カスタムクラスの定義" 'Public Class SalesRecord ' Public Area As String ' Public City As String ' Public Category As String ' Public Name As String ' Public Revenue As Integer 'End Class #End Region #Region "データの初期化" Dim record As New SalesRecord With { .Area = "北米", .City = "シカゴ", .Category = "家電製品", .Name = "Bose 785593-0050", .Revenue = 92800 } #End Region Dim worksheet As IWorksheet = workbook.Worksheets(0) ' セルにバインディングパスを設定 worksheet.Range!A1.BindingPath = "Area" worksheet.Range!B2.BindingPath = "City" worksheet.Range!C2.BindingPath = "Name" worksheet.Range!D3.BindingPath = "Revenue" ' データソースを設定 worksheet.DataSource = record ' xlsx ファイルに保存 workbook.Save("CellBinding.xlsx")