LibreOfficeDocTool.framework 1.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package LibreOfficeDocTool.framework --version 1.0.2                
NuGet\Install-Package LibreOfficeDocTool.framework -Version 1.0.2                
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.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add LibreOfficeDocTool.framework --version 1.0.2                
#r "nuget: LibreOfficeDocTool.framework, 1.0.2"                
#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.2

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

DocTool

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

1.初始化建構

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

private DocWordTool wordTool { get; set; }
public SampleCode1(string libreOfficeAppPath, string locationTempPath)
{
    this.wordTool = new DocWordTool(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.wordTool.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.wordTool.CreateRow();
                  x.ForEach(item => row.Append(this.wordTool.CreateCell(item)));
                  return row;
             }).ToList()
     }
};

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

public FileObj WordReplaceTag(FileObj fileData, Dictionary<string, ReplaceDto> replaceData)
{
     fileData = wordTool
        .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 = wordTool
        .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.8 122 6/13/2024
1.0.7 101 6/13/2024
1.0.6 72 6/5/2024
1.0.4 173 3/18/2024
1.0.2 156 3/18/2024
1.0.0 164 3/18/2024