// 新規ワークブックの作成 var workbook = new GrapeCity.Documents.Excel.Workbook(); // 帳票テンプレートを読み込む var templateFile = this.GetResourceStream("xlsx\\Template_PurchaseOrder.xlsx"); workbook.Open(templateFile); #region カスタムクラスの定義 //public class PurchaseOrderBasicInfo //{ // public string ID; // public DateTime OrderDate; // public string CreditTerms; // public string PONumber; // public string Ref; // public string DeliverToCompany; // public string DeliverToAddress; // public string PostalCode; // public string Country; //} #endregion #region データの初期化 var po = new DataTable(); po.Columns.Add(new DataColumn("s_no", typeof(Int32))); po.Columns.Add(new DataColumn("itemnumber", typeof(string))); po.Columns.Add(new DataColumn("itemdescription", typeof(string))); po.Columns.Add(new DataColumn("quantity", typeof(Int32))); po.Columns.Add(new DataColumn("um", typeof(string))); po.Columns.Add(new DataColumn("price", typeof(Int32))); po.Rows.Add(1, "P1001", "Pencils HB", 5, "dozen", 10); po.Rows.Add(2, "P1003", "Pencils 2B", 4, "dozen", 10); po.Rows.Add(3, "P1003", "Paper A4 - Photo Copier", 10, "ream", 3); po.Rows.Add(4, "P1234", "Pens - Ball point", 15, "boxes", 2); po.Rows.Add(5, "P3221", "Highligter", 8, "sets", 10); PurchaseOrderBasicInfo orderbasicInfo = new PurchaseOrderBasicInfo { ID = "US120499", OrderDate = new DateTime(2019, 7, 7), CreditTerms = "30", PONumber = "PO1011", Ref = "QT1231", DeliverToCompany = "Sanfort Pvt. Ltd.", DeliverToAddress = "1322, High Street, Geln Waverlay", PostalCode = "Victoria 3456", Country = "Australia" }; #endregion // データソースを追加 workbook.AddDataSource("po", po); workbook.AddDataSource("tax", 5); workbook.AddDataSource("ds", orderbasicInfo); // データを連結して帳票を作成 workbook.ProcessTemplate(); // xlsx ファイルに保存 workbook.Save("PurchaseOrder.xlsx");
' 新規ワークブックの作成 Dim workbook As New Workbook ' 帳票テンプレートを読み込む Dim templateFile = GetResourceStream("xlsx\Template_PurchaseOrder.xlsx") workbook.Open(templateFile) #Region "カスタムクラスの定義" 'Public Class PurchaseOrderBasicInfo ' Public ID As String ' Public OrderDate As Date ' Public CreditTerms As String ' Public PONumber As String ' Public Ref As String ' Public DeliverToCompany As String ' Public DeliverToAddress As String ' Public PostalCode As String ' Public Country As String 'End Class #End Region #Region "データの初期化" Dim po As New DataTable With po.Columns .Add(New DataColumn("s_no", GetType(Integer))) .Add(New DataColumn("itemnumber", GetType(String))) .Add(New DataColumn("itemdescription", GetType(String))) .Add(New DataColumn("quantity", GetType(Integer))) .Add(New DataColumn("um", GetType(String))) .Add(New DataColumn("price", GetType(Integer))) End With With po.Rows .Add(1, "P1001", "Pencils HB", 5, "dozen", 10) .Add(2, "P1003", "Pencils 2B", 4, "dozen", 10) .Add(3, "P1003", "Paper A4 - Photo Copier", 10, "ream", 3) .Add(4, "P1234", "Pens - Ball point", 15, "boxes", 2) .Add(5, "P3221", "Highligter", 8, "sets", 10) End With Dim orderbasicInfo As New PurchaseOrderBasicInfo With { .ID = "US120499", .OrderDate = #2019-7-7#, .CreditTerms = "30", .PONumber = "PO1011", .Ref = "QT1231", .DeliverToCompany = "Sanfort Pvt. Ltd.", .DeliverToAddress = "1322, High Street, Geln Waverlay", .PostalCode = "Victoria 3456", .Country = "Australia" } #End Region ' データソースを追加 workbook.AddDataSource("po", po) workbook.AddDataSource("tax", 5) workbook.AddDataSource("ds", orderbasicInfo) ' データを連結して帳票を作成 workbook.ProcessTemplate() ' xlsx ファイルに保存 workbook.Save("PurchaseOrder.xlsx")