//create a new workbook var workbook = new GrapeCity.Documents.Excel.Workbook(); //set worksheet layout and data IWorksheet worksheet = workbook.Worksheets[0]; worksheet.Range["A:A"].ColumnWidth = 2; worksheet.Range["B:C"].ColumnWidth = 15; worksheet.Range["D:G"].ColumnWidth = 25; worksheet.Range["4:14"].RowHeight = 57; worksheet.Range["B3"].Value = "Type"; worksheet.Range["C3"].Value = "Data"; worksheet.Range["B2"].Value = "Barcode"; worksheet.Range["B2:G2"].Merge(true); worksheet.Range["D3:G3"].Value = new object[,]{ {"Default", "Change color", "Change showLable", "Change lablePosition"} }; worksheet.PageSetup.PrintTitleColumns = "$A:$C"; worksheet.Range["B4:C14"].HorizontalAlignment = HorizontalAlignment.Center; worksheet.Range["B4:C14"].VerticalAlignment = VerticalAlignment.Center; worksheet.Range["B2:G3"].HorizontalAlignment = HorizontalAlignment.Center; worksheet.Range["B2:G3"].VerticalAlignment = VerticalAlignment.Center; worksheet.Range["B4:C14"].Value = new object[,] { {"QR code", "Policy:411"}, {"Data Matrix", "Policy:411"}, {"PDF417", 6935205311092}, {"EAN-8", 4137962}, {"EAN-13", 6920312296219}, {"Code39", 3934712708295}, {"Code93", 6945091701532}, {"Code49", 6901668002433}, {"Code128", 465465145645}, {"Codabar", 9787560044231}, {"gs1128", 235465143135} }; string[] types = { "BC_QRCODE", "BC_DataMatrix", "BC_PDF417", "BC_EAN8", "BC_EAN13", "BC_CODE39", "BC_CODE93", "BC_CODE49", "BC_CODE128", "BC_CODABAR", "BC_GS1_128" }; //use formula to add barcode for (var i = 0; i < types.Length; i++) { string columnD = "D" + (i + 4); string columnE = "E" + (i + 4); worksheet.Range[columnD].Formula = "=" + types[i] + "(C" + (i + 4) + ")"; worksheet.Range[columnE].Formula = "=" + types[i] + "(C" + (i + 4) + ",\"#fff\",\"#000\")"; } for (var i = 3; i < types.Length; i++) { string columnD = "F" + (i + 4); string columnE = "G" + (i + 4); worksheet.Range[columnD].Formula = "=" + types[i] + "(C" + (i + 4) + ",,,0)"; worksheet.Range[columnE].Formula = "=" + types[i] + "(C" + (i + 4) + ",,,,\"top\")"; } // Convert all barcode formula results to pictures. workbook.ConvertBarcodeToPicture();
' Create a new Workbook Dim workbook As New Workbook Dim worksheet As IWorksheet = workbook.Worksheets(0) worksheet.Range("B:C").ColumnWidth = 15 worksheet.Range("D:G").ColumnWidth = 25 worksheet.Range("4:14").RowHeight = 60 worksheet.Range("A:A").ColumnWidth = 2 worksheet.Range!B3.Value = "Type" worksheet.Range!C3.Value = "Data" worksheet.Range!B2.Value = "Barcode" worksheet.Range("B2:B3").Merge(True) worksheet.Range("C2:C3").Merge(True) worksheet.Range("B2:G2").Merge(True) worksheet.Range("D3:G3").Value = New Object(,) { {"Default", "Change color", "Change showLable", "Change lablePosition"}} worksheet.Range("B4:C14").Value = New Object(,) { {"QR code", "Policy:411"}, {"Data Matrix", "Policy:411"}, {"PDF417", 6935205311092}, {"EAN-8", 4137962}, {"EAN-13", 6920312296219}, {"Code39", 3934712708295}, {"Code93", 6945091701532}, {"Code49", 6901668002433}, {"Code128", 465465145645}, {"Codabar", 9787560044231}, {"gs1128", 235465143135}} Dim types As String() = {"BC_QRCODE", "BC_DataMatrix", "BC_PDF417", "BC_EAN8", "BC_EAN13", "BC_CODE39", "BC_CODE93", "BC_CODE49", "BC_CODE128", "BC_CODABAR", "BC_GS1_128"} worksheet.PageSetup.PrintGridlines = True For i = 0 To types.Length - 1 Dim columnD As String = "D" & (i + 4) Dim columnE As String = "E" & (i + 4) worksheet.Range(columnD).Formula = "=" & types(i) & "(C" & (i + 4) & ")" worksheet.Range(columnE).Formula = "=" & types(i) & "(C" & (i + 4) & ",""#fff"",""#000"")" Next For i = 3 To types.Length - 1 Dim columnD As String = "F" & (i + 4) Dim columnE As String = "G" & (i + 4) worksheet.Range(columnD).Formula = "=" & types(i) & "(C" & (i + 4) & ",,,0)" worksheet.Range(columnE).Formula = "=" & types(i) & "(C" & (i + 4) & ",,,,""top"")" Next ' Convert all barcode formula results to pictures. workbook.ConvertBarcodeToPicture() ' save to an excel file workbook.Save("ConvertBarcodeToPicture.xlsx")