diff --git a/BarcodeXlsx.sln b/BarcodeXlsx.sln index 06eed15..c27e4f2 100644 --- a/BarcodeXlsx.sln +++ b/BarcodeXlsx.sln @@ -10,11 +10,19 @@ Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {0B304859-4BAD-4587-A83A-B9EC64193680}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {0B304859-4BAD-4587-A83A-B9EC64193680}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0B304859-4BAD-4587-A83A-B9EC64193680}.Debug|x64.ActiveCfg = Debug|Any CPU + {0B304859-4BAD-4587-A83A-B9EC64193680}.Debug|x64.Build.0 = Debug|Any CPU + {0B304859-4BAD-4587-A83A-B9EC64193680}.Debug|x86.ActiveCfg = Debug|Any CPU + {0B304859-4BAD-4587-A83A-B9EC64193680}.Debug|x86.Build.0 = Debug|Any CPU {0B304859-4BAD-4587-A83A-B9EC64193680}.Release|Any CPU.ActiveCfg = Release|Any CPU {0B304859-4BAD-4587-A83A-B9EC64193680}.Release|Any CPU.Build.0 = Release|Any CPU {93B3605C-AE72-4A18-80E7-9510DC99A07E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU diff --git a/BarcodeXlsx/BarcodeXlsx.csproj b/BarcodeXlsx/BarcodeXlsx.csproj index fd37bae..65548c0 100644 --- a/BarcodeXlsx/BarcodeXlsx.csproj +++ b/BarcodeXlsx/BarcodeXlsx.csproj @@ -2,12 +2,16 @@ Exe - netcoreapp2.1 + netcoreapp2.2 + + + + diff --git a/BarcodeXlsx/DecodeArgumentParamaters.cs b/BarcodeXlsx/DecodeArgumentParamaters.cs index 3e0558a..a967e94 100644 --- a/BarcodeXlsx/DecodeArgumentParamaters.cs +++ b/BarcodeXlsx/DecodeArgumentParamaters.cs @@ -12,6 +12,10 @@ public string destinationFileName; public bool enabledVerbose = false; public bool enabledProgress = false; + public bool enabledLabel = false; + public bool enabledRemoveTag = false; + public int imageWidht = 256; + public int imageHeight = 64; public DecodeArgumentParamaters(string[] args) { @@ -24,6 +28,8 @@ bool destinationFlag = false; bool preCharsFlag = false; bool postCharsFlag = false; + bool imageWidthFlag = false; + bool imageHeightFlag = false; foreach (var arg in args) { @@ -43,6 +49,22 @@ { postCharsFlag = true; } + else if (arg == "-width") + { + imageWidthFlag = true; + } + else if (arg == "-height") + { + imageHeightFlag = true; + } + else if (arg == "-showlabel") + { + enabledLabel = true; + } + else if (arg == "-removetag") + { + enabledRemoveTag = true; + } else if (arg == "-progress") { enabledProgress = true; @@ -71,6 +93,22 @@ postCharsFlag = false; postChars = arg; } + else if (imageWidthFlag) + { + imageWidthFlag = false; + if (int.TryParse(arg, out imageWidht)) + { + + } + } + else if (imageHeightFlag) + { + imageHeightFlag = false; + if (int.TryParse(arg, out imageHeight)) + { + + } + } } } } diff --git a/BarcodeXlsx/Program.cs b/BarcodeXlsx/Program.cs index d5b8e51..8e2e1ee 100644 --- a/BarcodeXlsx/Program.cs +++ b/BarcodeXlsx/Program.cs @@ -10,6 +10,8 @@ using ClosedXML.Excel; using ClosedXML.Excel.Drawings; +using ImageMagick; + namespace BarcodeXlsx { class Program @@ -18,8 +20,15 @@ { try { + Console.WriteLine("BarcodeXlsx v0.1"); + DecodeArgumentParamaters param = new DecodeArgumentParamaters(args); + if (param.enabledVerbose) + { + Console.WriteLine("--source {0}", param.sourceFileName); + } + XLWorkbook book = new XLWorkbook(param.sourceFileName); foreach (var sheet in book.Worksheets) { @@ -48,21 +57,35 @@ try { BarcodeLib.Barcode barcode = new BarcodeLib.Barcode(); - barcode.Height = 256; - barcode.Width = 512; + barcode.Height = param.imageHeight; + barcode.Width = param.imageWidht; barcode.Alignment = BarcodeLib.AlignmentPositions.CENTER; + barcode.IncludeLabel = param.enabledLabel; + barcode.LabelPosition = BarcodeLib.LabelPositions.BOTTOMCENTER; + barcode.LabelFont = new Font(FontFamily.GenericSansSerif, 8); barcode.BackColor = Color.White; barcode.ImageFormat = ImageFormat.Bmp; - barcode.LabelPosition = BarcodeLib.LabelPositions.BOTTOMCENTER; barcode.Encode(DecodeBarcodeStyle(barcodeType), barcodeValue); - MemoryStream tempStream = new MemoryStream(); - barcode.EncodedImage.Save(tempStream, ImageFormat.Png); - var picture = sheet.AddPicture(tempStream); + MemoryStream tempStream1 = new MemoryStream(); + barcode.EncodedImage.Save(tempStream1, ImageFormat.Png); + + tempStream1.Position = 0; + MagickImage image = new MagickImage(tempStream1); + image.Transparent(MagickColors.White); + MemoryStream tempStream2 = new MemoryStream(); + image.Write(tempStream2, MagickFormat.Png); + + var picture = sheet.AddPicture(tempStream2); picture.MoveTo(cell); picture.Scale(0.5, true); picture.Height = (int)(cell.WorksheetRow().Height / 0.75); picture.Width = (int)(cell.WorksheetColumn().Width / 0.118); + + if (param.enabledRemoveTag) + { + cell.SetValue(""); + } } catch (Exception exp) { diff --git a/BarcodeXlsx/Properties/launchSettings.json b/BarcodeXlsx/Properties/launchSettings.json index bd35be1..b1dc9a4 100644 --- a/BarcodeXlsx/Properties/launchSettings.json +++ b/BarcodeXlsx/Properties/launchSettings.json @@ -2,7 +2,7 @@ "profiles": { "BarcodeXlsx": { "commandName": "Project", - "commandLineArgs": "-source C:\\Users\\mikah\\Desktop\\Book1.xlsx -verbose" + "commandLineArgs": "-source C:\\Users\\07121\\Desktop\\Book1.xlsx -verbose -removetag" } } } \ No newline at end of file