06-18-2023, 09:38 PM
I'm still using the old EPPlus DLLs compiled from the code in the archived repository. You can see from the code I've got the DLL stashed in a folder where I keep DLLs, and loaded it from there via Properties -> Library.
The older EPPlus license is LGPL, not the newer one you might have to pay for. The RIPTutorial EPPlus pages should be a big help, I haven't gone through them all but they look good.
You'll see a reference to Encoding.RegisterProvider(CodePagesEncodingProvider.Instance), and to System.Text.Encoding.CodePages. I followed instructions from this Medium page. You may not need them if you copy from the code below. Maybe you won't need this - I needed it because of an error regarding codepage 437 I kept getting. Maybe that's not something the newer version of EPPlus will throw, but I haven't tried it. YMMV. Also there's no error checking - File.Delete() doesn't throw any error if there's no file to delete, so for now I've left it at that. I guess a "Directory not found" exception might get thrown in some instances, but since I've set it to my Downloads folder that's not going to happen here.
Also notice that the Cookbook example's reference to the license isn't needed for the DLL I'm using.
I've worked with EPPlus in the past (although a number of years ago now and with AutoHotkey using the CLR lib). As I recall you can create charts, pivot tables, really lots of stuff. I can see why the author decided to monetize it, he sure put a lot of work in it. Kudos, Jan Kallman!
Regards,
burque505
The older EPPlus license is LGPL, not the newer one you might have to pay for. The RIPTutorial EPPlus pages should be a big help, I haven't gone through them all but they look good.
You'll see a reference to Encoding.RegisterProvider(CodePagesEncodingProvider.Instance), and to System.Text.Encoding.CodePages. I followed instructions from this Medium page. You may not need them if you copy from the code below. Maybe you won't need this - I needed it because of an error regarding codepage 437 I kept getting. Maybe that's not something the newer version of EPPlus will throw, but I haven't tried it. YMMV. Also there's no error checking - File.Delete() doesn't throw any error if there's no file to delete, so for now I've left it at that. I guess a "Directory not found" exception might get thrown in some instances, but since I've set it to my Downloads folder that's not going to happen here.
Also notice that the Cookbook example's reference to the license isn't needed for the DLL I'm using.
I've worked with EPPlus in the past (although a number of years ago now and with AutoHotkey using the CLR lib). As I recall you can create charts, pivot tables, really lots of stuff. I can see why the author decided to monetize it, he sure put a lot of work in it. Kudos, Jan Kallman!
/*/ r %folders.Documents%\LibreAutomate\DLLs\EPPlus.dll; nuget MS_Misc\System.Text.Encoding.CodePages; /*/
using OfficeOpenXml;
using System;
using System.IO;
using System.Drawing;
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
// https://chsamii.medium.com/no-data-is-available-for-encoding-1252-8bc14651d631
File.Delete(folders.Downloads + "smoke_test.xlsx");
string file = folders.Downloads + "smoke_test.xlsx";
using(var pck = new ExcelPackage(new FileInfo(file))) {
dynamic Worksheet = pck.Workbook.Worksheets.Add("Sheet1");
Worksheet.Cells["A1"].LoadFromText("LibreAutomate did this!!!");
double minW = 60.0;
Worksheet.Cells["A1:C3"].AutoFitColumns(minW);
Worksheet.Cells["A1"].Style.Font.Name = "Comic Sans MS";
Worksheet.Cells["A1"].Style.Font.Size = 24;
Worksheet.Cells["A1"].Style.Font.Color.SetColor(Color.DarkTurquoise);
Worksheet.Cells["A1"].Style.WrapText = true;
Worksheet.Cells["A2:C2"].LoadFromText("Howard the Ape,filches,bananas!");
// Merge a range of cells
dynamic Rng = Worksheet.Cells["A3:C12"];
Rng.Style.WrapText = true;
string lorem = @"Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Maecenas porttitor congue massa.
Fusce posuere, magna sed pulvinar ultricies, purus lectus malesuada libero, sit amet commodo magna eros quis urna.
Nunc viverra imperdiet enim. Fusce est. Vivamus a tellus.
";
Rng.Merge = true;
Rng.Style.Font.Size = 16;
Rng.Style.Font.Bold = true;
Rng.Style.Font.Italic = true;
Rng.Style.Font.Color.SetColor(Color.DodgerBlue);
Rng.Value = lorem;
Worksheet.Cells["A1"].Style.Font.Bold = true;
Worksheet.Cells["A1:C3"].AutoFitColumns(minW);
pck.Save();
}
Regards,
burque505