1- using SixLabors . ImageSharp ;
2- using SixLabors . ImageSharp . PixelFormats ;
1+ using Microsoft . Office . Interop . Excel ;
2+ using System ;
3+ using System . IO ;
4+ using System . Runtime . InteropServices ;
35using System . Threading . Tasks ;
4- using ZXing . Common ;
5- using ZXing . Rendering ;
66
77namespace GithubActionsHelloWorld
88{
99 public class Program
1010 {
1111 public static async Task Main ( string [ ] args )
1212 {
13- var barcodeWriter = new ZXing . BarcodeWriterPixelData
13+ CreateExcelDocument ( ) ;
14+ }
15+
16+ private static void CreateExcelDocument ( )
17+ {
18+ Microsoft . Office . Interop . Excel . Application excelApplication = null ;
19+
20+ try
1421 {
15- Format = ZXing . BarcodeFormat . CODE_128 ,
16- Options = new EncodingOptions
17- {
18- Height = 300 ,
19- Width = 300 ,
20- } ,
21- Renderer = new PixelDataRenderer
22+ excelApplication = new
23+ Microsoft . Office . Interop . Excel . Application ( ) ;
24+ Workbook excelWorkBook = excelApplication . Workbooks . Add ( ) ;
25+ Worksheet worksheet = ( Worksheet ) excelWorkBook . Worksheets [ 1 ] ;
26+ worksheet . Cells [ 1 , 1 ] = "Product Id" ;
27+ worksheet . Cells [ 1 , 2 ] = "Product Name" ;
28+ worksheet . Cells [ 2 , 1 ] = "1" ;
29+ worksheet . Cells [ 2 , 2 ] = "Lenovo Laptop" ;
30+ worksheet . Cells [ 3 , 1 ] = "2" ;
31+ worksheet . Cells [ 3 , 2 ] = "DELL Laptop" ;
32+ var path = Path . GetTempFileName ( ) + ".xlsx" ;
33+ Console . WriteLine ( path ) ;
34+ excelWorkBook . SaveAs ( Path . Combine ( path ) ) ;
35+ }
36+ catch ( Exception ex )
37+ {
38+ Console . WriteLine ( ex . Message ) ;
39+ }
40+ finally
41+ {
42+ if ( excelApplication != null )
2243 {
44+ excelApplication . Quit ( ) ;
45+ Marshal . FinalReleaseComObject ( excelApplication ) ;
2346 }
24- } ;
25-
26- var pixelData = barcodeWriter . Write ( "Hallo Barcode" ) ;
27-
28- using ( var image = Image . LoadPixelData < Rgba32 > ( pixelData . Pixels , 300 , 300 ) )
29- await image . SaveAsBmpAsync ( "barcode.bmp" ) ;
47+ }
3048 }
3149 }
3250}
0 commit comments