LibreOfficeDocTool.framework 1.0.4

dotnet add package LibreOfficeDocTool.framework --version 1.0.4
NuGet\Install-Package LibreOfficeDocTool.framework -Version 1.0.4
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="LibreOfficeDocTool.framework" Version="1.0.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add LibreOfficeDocTool.framework --version 1.0.4
#r "nuget: LibreOfficeDocTool.framework, 1.0.4"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install LibreOfficeDocTool.framework as a Cake Addin
#addin nuget:?package=LibreOfficeDocTool.framework&version=1.0.4

// Install LibreOfficeDocTool.framework as a Cake Tool
#tool nuget:?package=LibreOfficeDocTool.framework&version=1.0.4

DocTool

使用LibreOffice,將word文件轉pdf以及製作word文件,請先於主機上下載LibreOffice

1.初始化建構

libreOfficeAppPath:LibreOffice路徑位置(\LibreOfficePortable\App\libreoffice\program\soffice.exe)
locationTempPath:指定文件暫時存放位置

private Tool docTool { get; set; }
public SampleCode1(string libreOfficeAppPath, string locationTempPath)
{
    this.docTool = new Tool(libreOfficeAppPath, locationTempPath);
}

.

2.Word文件替換關鍵字範例

ReplaceType型態
0:Text(文字)
1:Table(表格)
2:Image(圖片)
3:HtmlString(HTML)
4:TableRow(表格-列)

var replaceData = new Dictionary<string, ReplaceDto>()
{
     ["PONo"] = new ReplaceDto() { textStr = "11300000A1" },
     ["BarCode1_Image"] = new ReplaceDto()
     {
         replaceType = ReplaceType.Image,
         fileName = "barcode",
         fileType = "jpg",
         fileByteArr = new byte[0],
         imageDpi = 72,
         imageHeight = 30,
         imageWidth = 150,
     },
     ["PoVenTable"] = new ReplaceDto()
     {
         replaceType = ReplaceType.Table,
         tableData = this.docTool.Word.ToXMLTable(new List<string>() { "品名", "數量", "總價" }, new List<List<string>>() { new List<string>() { "A", "1", "1500" } }),
     },
     ["AppP_Table"] = new ReplaceDto()
     {
         replaceType = ReplaceType.HtmlString,
         htmlStr = "<p style=\"background-color:Tomato;\">Lorem ipsum...</p>",
     },
     ["AppP2_TableRow"] = new ReplaceDto()
     {
         replaceType = ReplaceType.TableRow,
         tableRowDatas = new List<List<string>>() { new List<string>() { "A", "1", "1500" } }
             .Select(x =>
             {
                  var row = this.docTool.Word.CreateRow();
                  x.ForEach(item => row.Append(this.docTool.Word.CreateCell(item)));
                  return row;
             }).ToList()
     }
};

fileData:附件
replaceData:取代資料
確保文件內的標籤是{$Tag$}並加上highlight樣式,如右圖tag

public FileObj WordReplaceTag(FileObj fileData, Dictionary<string, ReplaceDto> replaceData)
{
     fileData = docTool.Word
        .ReplaceTag($"{fileData.fileName}.{fileData.fileType}", fileData.fileByteArr, replaceData)
        .GetData();
    return fileData;
}

.

3.轉PDF範例

fileData:附件 **目前只接受.doc、.docx、.odt、.xls、.xlsx、.htm、.html

public FileObj WordToPdf(FileObj fileData)
{
    fileData = docTool.Word
        .ToPDF($"{fileData.fileName}.{fileData.fileType}", fileData.fileByteArr)
        .GetData();
    return fileData;
}
Product Compatible and additional computed target framework versions.
.NET Framework net472 is compatible.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.4 143 3/18/2024
1.0.2 126 3/18/2024
1.0.0 137 3/18/2024