committed by
GitHub
40 changed files with 734 additions and 8 deletions
@ -1,3 +1,3 @@ |
|||||
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd"> |
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd"> |
||||
<ConfigureAwait /> |
<ConfigureAwait ContinueOnCapturedContext="false" /> |
||||
</Weavers> |
</Weavers> |
||||
@ -0,0 +1,3 @@ |
|||||
|
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd"> |
||||
|
<ConfigureAwait ContinueOnCapturedContext="false" /> |
||||
|
</Weavers> |
||||
@ -0,0 +1,30 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> |
||||
|
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. --> |
||||
|
<xs:element name="Weavers"> |
||||
|
<xs:complexType> |
||||
|
<xs:all> |
||||
|
<xs:element name="ConfigureAwait" minOccurs="0" maxOccurs="1"> |
||||
|
<xs:complexType> |
||||
|
<xs:attribute name="ContinueOnCapturedContext" type="xs:boolean" /> |
||||
|
</xs:complexType> |
||||
|
</xs:element> |
||||
|
</xs:all> |
||||
|
<xs:attribute name="VerifyAssembly" type="xs:boolean"> |
||||
|
<xs:annotation> |
||||
|
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation> |
||||
|
</xs:annotation> |
||||
|
</xs:attribute> |
||||
|
<xs:attribute name="VerifyIgnoreCodes" type="xs:string"> |
||||
|
<xs:annotation> |
||||
|
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation> |
||||
|
</xs:annotation> |
||||
|
</xs:attribute> |
||||
|
<xs:attribute name="GenerateXsd" type="xs:boolean"> |
||||
|
<xs:annotation> |
||||
|
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation> |
||||
|
</xs:annotation> |
||||
|
</xs:attribute> |
||||
|
</xs:complexType> |
||||
|
</xs:element> |
||||
|
</xs:schema> |
||||
@ -0,0 +1,21 @@ |
|||||
|
<Project Sdk="Microsoft.NET.Sdk"> |
||||
|
|
||||
|
<Import Project="..\..\..\..\configureawait.props" /> |
||||
|
<Import Project="..\..\..\..\common.props" /> |
||||
|
|
||||
|
<PropertyGroup> |
||||
|
<TargetFrameworks>net8.0;net9.0</TargetFrameworks> |
||||
|
<AssemblyName>LINGYUN.Abp.Exporter.Pdf.LibreOffice</AssemblyName> |
||||
|
<PackageId>LINGYUN.Abp.Exporter.Pdf.LibreOffice</PackageId> |
||||
|
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> |
||||
|
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> |
||||
|
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> |
||||
|
<Nullable>enable</Nullable> |
||||
|
<RootNamespace /> |
||||
|
</PropertyGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<ProjectReference Include="..\LINGYUN.Abp.Exporter.Pdf\LINGYUN.Abp.Exporter.Pdf.csproj" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
</Project> |
||||
@ -0,0 +1,22 @@ |
|||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Volo.Abp.Modularity; |
||||
|
|
||||
|
namespace LINGYUN.Abp.Exporter.Pdf.LibreOffice; |
||||
|
|
||||
|
[DependsOn(typeof(AbpExporterPdfModule))] |
||||
|
public class AbpExporterPdfLibreOfficeModule : AbpModule |
||||
|
{ |
||||
|
public override void ConfigureServices(ServiceConfigurationContext context) |
||||
|
{ |
||||
|
// 解决单元测试问题
|
||||
|
if (context.Services.IsAdded<LibreOfficeTestEnvironment>()) |
||||
|
{ |
||||
|
return; |
||||
|
} |
||||
|
if (!LibreOfficeCommands.IsLibreOffliceInstalled()) |
||||
|
{ |
||||
|
throw new Volo.Abp.AbpInitializationException("Libreoffice not installed in the current operation environment of the host, please refer to the document after installation using ` AbpExporterPdfLibreOfficeModule ` module."); |
||||
|
} |
||||
|
context.Services.AddTransient<IExcelToPdfProvider, LibreOfficeExcelToPdfProvider>(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,103 @@ |
|||||
|
using System; |
||||
|
using System.Diagnostics; |
||||
|
using System.IO; |
||||
|
using System.Threading; |
||||
|
using System.Threading.Tasks; |
||||
|
|
||||
|
namespace LINGYUN.Abp.Exporter.Pdf.LibreOffice; |
||||
|
|
||||
|
public class LibreOfficeCommands |
||||
|
{ |
||||
|
public static string WindowsCli { get; set; } = "soffice.com"; |
||||
|
public static string WindowsCliDir { get; set; } = "C:\\Program Files\\LibreOffice\\program\\"; |
||||
|
|
||||
|
public static string UnixCli { get; set; } = "libreoffice"; |
||||
|
public static string UnixCliDir { get; set; } = ""; |
||||
|
|
||||
|
public static string GetCli() |
||||
|
{ |
||||
|
if (OperatingSystem.IsWindows()) |
||||
|
{ |
||||
|
return Path.Combine(WindowsCliDir, WindowsCli); |
||||
|
} |
||||
|
|
||||
|
// 详细的操作系统版本: https://zh-cn.libreoffice.org/get-help/system-requirements/
|
||||
|
if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) |
||||
|
{ |
||||
|
return Path.Combine(UnixCliDir, UnixCli); |
||||
|
} |
||||
|
|
||||
|
throw new PlatformNotSupportedException($"The current platform {Environment.OSVersion.ToString()} does not support the libreoffice runtime library"); |
||||
|
} |
||||
|
|
||||
|
public static bool IsLibreOffliceInstalled() |
||||
|
{ |
||||
|
return LibreOfficeCommands.IsLibreOfficeAvailable(GetCli()); |
||||
|
} |
||||
|
/// <summary>
|
||||
|
/// LibreOffice是否可用
|
||||
|
/// </summary>
|
||||
|
/// <param name="commandFile"></param>
|
||||
|
/// <returns></returns>
|
||||
|
public static bool IsLibreOfficeAvailable(string commandFile) |
||||
|
{ |
||||
|
try |
||||
|
{ |
||||
|
var process = new Process |
||||
|
{ |
||||
|
StartInfo = new ProcessStartInfo |
||||
|
{ |
||||
|
FileName = commandFile, |
||||
|
Arguments = "--version", |
||||
|
RedirectStandardOutput = true, |
||||
|
RedirectStandardError = true, |
||||
|
UseShellExecute = false, |
||||
|
CreateNoWindow = true |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
process.Start(); |
||||
|
var output = process.StandardOutput.ReadToEnd(); |
||||
|
|
||||
|
process.WaitForExit(); |
||||
|
|
||||
|
return process.ExitCode == 0 && output.Contains("LibreOffice"); |
||||
|
} |
||||
|
catch |
||||
|
{ |
||||
|
return false; |
||||
|
} |
||||
|
} |
||||
|
/// <summary>
|
||||
|
/// Excel转换为Pdf
|
||||
|
/// </summary>
|
||||
|
/// <param name="excelFile"></param>
|
||||
|
/// <param name="outputPath"></param>
|
||||
|
/// <exception cref="Exception"></exception>
|
||||
|
public async static Task ExcelToPdf(string excelFile, string outputPath, CancellationToken cancellationToken = default) |
||||
|
{ |
||||
|
cancellationToken.ThrowIfCancellationRequested(); |
||||
|
|
||||
|
var start = new ProcessStartInfo |
||||
|
{ |
||||
|
FileName = GetCli(), |
||||
|
Arguments = $"--headless --convert-to pdf \"{excelFile}\" --outdir \"{outputPath}\"", |
||||
|
RedirectStandardOutput = true, |
||||
|
UseShellExecute = false, |
||||
|
CreateNoWindow = true, |
||||
|
}; |
||||
|
|
||||
|
var process = new Process |
||||
|
{ |
||||
|
StartInfo = start, |
||||
|
}; |
||||
|
process.Start(); |
||||
|
|
||||
|
await process.WaitForExitAsync(cancellationToken); |
||||
|
|
||||
|
if (process.ExitCode != 0) |
||||
|
{ |
||||
|
throw new Exception($"Excel failed to convert to PDF. Error code: {process.ExitCode}"); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,52 @@ |
|||||
|
using System; |
||||
|
using System.IO; |
||||
|
using System.Threading; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.IO; |
||||
|
|
||||
|
namespace LINGYUN.Abp.Exporter.Pdf.LibreOffice; |
||||
|
public class LibreOfficeExcelToPdfProvider : IExcelToPdfProvider |
||||
|
{ |
||||
|
public async virtual Task<Stream> ParseAsync(Stream excelStream, CancellationToken cancellationToken = default) |
||||
|
{ |
||||
|
var outputPath = Path.Combine(Path.GetTempPath(), "excel2pdf"); |
||||
|
|
||||
|
DirectoryHelper.CreateIfNotExists(outputPath); |
||||
|
|
||||
|
var templateFileId = Guid.NewGuid().ToString(); |
||||
|
var tempExcelFile = Path.Combine(outputPath, $"{templateFileId}.xlsx"); |
||||
|
var tempPdfFile = Path.Combine(outputPath, $"{templateFileId}.pdf"); |
||||
|
|
||||
|
try |
||||
|
{ |
||||
|
if (!File.Exists(tempExcelFile)) |
||||
|
{ |
||||
|
using (var excelFile = File.Create(tempExcelFile)) |
||||
|
{ |
||||
|
await excelStream.CopyToAsync(excelFile, cancellationToken); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
await LibreOfficeCommands.ExcelToPdf(tempExcelFile, outputPath, cancellationToken); |
||||
|
|
||||
|
var pdfStream = new MemoryStream(); |
||||
|
|
||||
|
using (var pdfFileStream = File.OpenRead(tempPdfFile)) |
||||
|
{ |
||||
|
await pdfFileStream.CopyToAsync(pdfStream, cancellationToken); |
||||
|
pdfStream.Seek(0, SeekOrigin.Begin); |
||||
|
} |
||||
|
|
||||
|
return pdfStream; |
||||
|
} |
||||
|
catch |
||||
|
{ |
||||
|
throw; |
||||
|
} |
||||
|
finally |
||||
|
{ |
||||
|
FileHelper.DeleteIfExists(tempExcelFile); |
||||
|
FileHelper.DeleteIfExists(tempPdfFile); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,4 @@ |
|||||
|
namespace LINGYUN.Abp.Exporter.Pdf.LibreOffice; |
||||
|
public class LibreOfficeTestEnvironment |
||||
|
{ |
||||
|
} |
||||
@ -0,0 +1,26 @@ |
|||||
|
# LINGYUN.Abp.Exporter.Pdf.LibreOffice |
||||
|
|
||||
|
> LibreOffice is Free and Open Source Software. Development is open to new talent and new ideas, and our software is tested and used daily by a large and devoted user community. |
||||
|
|
||||
|
此模块使用本地 `LibreOffice` 命令行实现将Excel转换为Pdf, 请引用此模块前确保已安装有 `LibreOffice`, 如未安装在默认目录, 请在使用前手动指定安装目录. |
||||
|
|
||||
|
## 配置使用 |
||||
|
|
||||
|
|
||||
|
```csharp |
||||
|
|
||||
|
[DependsOn( |
||||
|
typeof(AbpExporterPdfLibreOfficeModule) |
||||
|
)] |
||||
|
public class YouProjectModule : AbpModule |
||||
|
{ |
||||
|
public override void PreConfigureServices(ServiceConfigurationContext context) |
||||
|
{ |
||||
|
// 手动指定安装目录 |
||||
|
LibreOfficeCommands.WindowsCliDir = "path\\to\\libreoffice"; |
||||
|
LibreOfficeCommands.UnixCliDir = "path/to/libreoffice"; |
||||
|
} |
||||
|
} |
||||
|
``` |
||||
|
|
||||
|
|
||||
@ -0,0 +1,3 @@ |
|||||
|
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd"> |
||||
|
<ConfigureAwait ContinueOnCapturedContext="false" /> |
||||
|
</Weavers> |
||||
@ -0,0 +1,30 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> |
||||
|
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. --> |
||||
|
<xs:element name="Weavers"> |
||||
|
<xs:complexType> |
||||
|
<xs:all> |
||||
|
<xs:element name="ConfigureAwait" minOccurs="0" maxOccurs="1"> |
||||
|
<xs:complexType> |
||||
|
<xs:attribute name="ContinueOnCapturedContext" type="xs:boolean" /> |
||||
|
</xs:complexType> |
||||
|
</xs:element> |
||||
|
</xs:all> |
||||
|
<xs:attribute name="VerifyAssembly" type="xs:boolean"> |
||||
|
<xs:annotation> |
||||
|
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation> |
||||
|
</xs:annotation> |
||||
|
</xs:attribute> |
||||
|
<xs:attribute name="VerifyIgnoreCodes" type="xs:string"> |
||||
|
<xs:annotation> |
||||
|
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation> |
||||
|
</xs:annotation> |
||||
|
</xs:attribute> |
||||
|
<xs:attribute name="GenerateXsd" type="xs:boolean"> |
||||
|
<xs:annotation> |
||||
|
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation> |
||||
|
</xs:annotation> |
||||
|
</xs:attribute> |
||||
|
</xs:complexType> |
||||
|
</xs:element> |
||||
|
</xs:schema> |
||||
@ -0,0 +1,25 @@ |
|||||
|
<Project Sdk="Microsoft.NET.Sdk"> |
||||
|
|
||||
|
<Import Project="..\..\..\..\configureawait.props" /> |
||||
|
<Import Project="..\..\..\..\common.props" /> |
||||
|
|
||||
|
<PropertyGroup> |
||||
|
<TargetFrameworks>net8.0;net9.0</TargetFrameworks> |
||||
|
<AssemblyName>LINGYUN.Abp.Exporter.Pdf.SpireLib</AssemblyName> |
||||
|
<PackageId>LINGYUN.Abp.Exporter.Pdf.SpireLib</PackageId> |
||||
|
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> |
||||
|
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> |
||||
|
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> |
||||
|
<Nullable>enable</Nullable> |
||||
|
<RootNamespace /> |
||||
|
</PropertyGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<PackageReference Include="Spire.XLS" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<ProjectReference Include="..\LINGYUN.Abp.Exporter.Pdf\LINGYUN.Abp.Exporter.Pdf.csproj" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
</Project> |
||||
@ -0,0 +1,13 @@ |
|||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Volo.Abp.Modularity; |
||||
|
|
||||
|
namespace LINGYUN.Abp.Exporter.Pdf.SpireLib; |
||||
|
|
||||
|
[DependsOn(typeof(AbpExporterPdfModule))] |
||||
|
public class AbpExporterPdfSpireLibModule : AbpModule |
||||
|
{ |
||||
|
public override void ConfigureServices(ServiceConfigurationContext context) |
||||
|
{ |
||||
|
context.Services.AddTransient<IExcelToPdfProvider, SpireExcelToPdfProvider>(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,20 @@ |
|||||
|
using Spire.Xls; |
||||
|
using System.IO; |
||||
|
using System.Threading; |
||||
|
using System.Threading.Tasks; |
||||
|
|
||||
|
namespace LINGYUN.Abp.Exporter.Pdf.SpireLib; |
||||
|
|
||||
|
public class SpireExcelToPdfProvider : IExcelToPdfProvider |
||||
|
{ |
||||
|
public virtual Task<Stream> ParseAsync(Stream excelStream, CancellationToken cancellationToken = default) |
||||
|
{ |
||||
|
using var workBook = new Workbook(); |
||||
|
Stream memoryStream = new MemoryStream(); |
||||
|
workBook.LoadFromStream(excelStream); |
||||
|
var workSheet = workBook.Worksheets[0]; |
||||
|
workSheet.SaveToPdfStream(memoryStream); |
||||
|
|
||||
|
return Task.FromResult(memoryStream); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,25 @@ |
|||||
|
# LINGYUN.Abp.Exporter.Pdf.SpireLib |
||||
|
|
||||
|
> Spire.XLS for .NET 是一款专业的 .NET Excel 组件, 它可以用在各种 .NET 框架中,包括 .NET Core、.NET 5.0、.NET 6.0、.NET 7.0、.NET Standard、 Xamarin、Mono Android、ASP.NET 和 Windows Forms 等相关的 .NET 应用程序。Spire.XLS for .NET 提供了一个对象模型 Excel API,使开发人员可以快速地在 .NET 平台上完成对 Excel 的各种编程操作,如根据模板创建新的 Excel 文档,编辑现有 Excel 文档以及对 Excel 文档进行转换。 |
||||
|
|
||||
|
此模块使用 [Spire.XLS](https://www.e-iceblue.cn/spirexls/spire-xls-for-net-program-guide-content.html) 实现将Excel转换为Pdf,请在使用前配置许可. |
||||
|
|
||||
|
## 配置使用 |
||||
|
|
||||
|
|
||||
|
```csharp |
||||
|
|
||||
|
[DependsOn( |
||||
|
typeof(AbpExporterPdfModule) |
||||
|
)] |
||||
|
public class YouProjectModule : AbpModule |
||||
|
{ |
||||
|
public override void PreConfigureServices(ServiceConfigurationContext context) |
||||
|
{ |
||||
|
// 配置许可 |
||||
|
Spire.Xls.License.LicenseProvider.SetLicense("xxx"); |
||||
|
} |
||||
|
} |
||||
|
``` |
||||
|
|
||||
|
|
||||
@ -0,0 +1,3 @@ |
|||||
|
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd"> |
||||
|
<ConfigureAwait ContinueOnCapturedContext="false" /> |
||||
|
</Weavers> |
||||
@ -0,0 +1,30 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> |
||||
|
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. --> |
||||
|
<xs:element name="Weavers"> |
||||
|
<xs:complexType> |
||||
|
<xs:all> |
||||
|
<xs:element name="ConfigureAwait" minOccurs="0" maxOccurs="1"> |
||||
|
<xs:complexType> |
||||
|
<xs:attribute name="ContinueOnCapturedContext" type="xs:boolean" /> |
||||
|
</xs:complexType> |
||||
|
</xs:element> |
||||
|
</xs:all> |
||||
|
<xs:attribute name="VerifyAssembly" type="xs:boolean"> |
||||
|
<xs:annotation> |
||||
|
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation> |
||||
|
</xs:annotation> |
||||
|
</xs:attribute> |
||||
|
<xs:attribute name="VerifyIgnoreCodes" type="xs:string"> |
||||
|
<xs:annotation> |
||||
|
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation> |
||||
|
</xs:annotation> |
||||
|
</xs:attribute> |
||||
|
<xs:attribute name="GenerateXsd" type="xs:boolean"> |
||||
|
<xs:annotation> |
||||
|
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation> |
||||
|
</xs:annotation> |
||||
|
</xs:attribute> |
||||
|
</xs:complexType> |
||||
|
</xs:element> |
||||
|
</xs:schema> |
||||
@ -0,0 +1,21 @@ |
|||||
|
<Project Sdk="Microsoft.NET.Sdk"> |
||||
|
|
||||
|
<Import Project="..\..\..\..\configureawait.props" /> |
||||
|
<Import Project="..\..\..\..\common.props" /> |
||||
|
|
||||
|
<PropertyGroup> |
||||
|
<TargetFrameworks>netstandard2.0;netstandard2.1;net8.0;net9.0</TargetFrameworks> |
||||
|
<AssemblyName>LINGYUN.Abp.Exporter.Pdf</AssemblyName> |
||||
|
<PackageId>LINGYUN.Abp.Exporter.Pdf</PackageId> |
||||
|
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> |
||||
|
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> |
||||
|
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> |
||||
|
<Nullable>enable</Nullable> |
||||
|
<RootNamespace /> |
||||
|
</PropertyGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<PackageReference Include="Volo.Abp.Core" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
</Project> |
||||
@ -0,0 +1,8 @@ |
|||||
|
using Volo.Abp.Modularity; |
||||
|
|
||||
|
namespace LINGYUN.Abp.Exporter.Pdf; |
||||
|
|
||||
|
public class AbpExporterPdfModule : AbpModule |
||||
|
{ |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,10 @@ |
|||||
|
using System.IO; |
||||
|
using System.Threading; |
||||
|
using System.Threading.Tasks; |
||||
|
|
||||
|
namespace LINGYUN.Abp.Exporter.Pdf; |
||||
|
|
||||
|
public interface IExcelToPdfProvider |
||||
|
{ |
||||
|
Task<Stream> ParseAsync(Stream excelStream, CancellationToken cancellationToken = default); |
||||
|
} |
||||
@ -0,0 +1,15 @@ |
|||||
|
using System.IO; |
||||
|
using System.Threading; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
|
||||
|
namespace LINGYUN.Abp.Exporter.Pdf; |
||||
|
|
||||
|
[Dependency(TryRegister = true)] |
||||
|
public class OriginalExcelToPdfProvider : IExcelToPdfProvider, ISingletonDependency |
||||
|
{ |
||||
|
public virtual Task<Stream> ParseAsync(Stream excelStream, CancellationToken cancellationToken = default) |
||||
|
{ |
||||
|
return Task.FromResult(excelStream); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,38 @@ |
|||||
|
# LINGYUN.Abp.Exporter.Pdf |
||||
|
|
||||
|
Pdf导出模块 |
||||
|
|
||||
|
## 配置使用 |
||||
|
|
||||
|
|
||||
|
```csharp |
||||
|
|
||||
|
[DependsOn( |
||||
|
typeof(AbpExporterPdfModule) |
||||
|
)] |
||||
|
public class YouProjectModule : AbpModule |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
``` |
||||
|
|
||||
|
> 导出数据 |
||||
|
```csharp |
||||
|
public class ExportDemoClass |
||||
|
{ |
||||
|
private readonly IExcelToPdfProvider _exporterProvider; |
||||
|
|
||||
|
public ExportDemoClass(IExcelToPdfProvider exporterProvider) |
||||
|
{ |
||||
|
_exporterProvider = exporterProvider; |
||||
|
} |
||||
|
|
||||
|
public async virtual Task<IRemoteStreamContent> ExportAsync(Stream excelStream) |
||||
|
{ |
||||
|
var stream = await _exporterProvider.ParseAsync(excelStream); |
||||
|
|
||||
|
return new RemoteStreamContent(stream, "demo.pdf"); |
||||
|
} |
||||
|
} |
||||
|
``` |
||||
|
|
||||
@ -0,0 +1,20 @@ |
|||||
|
<Project Sdk="Microsoft.NET.Sdk"> |
||||
|
|
||||
|
<PropertyGroup> |
||||
|
<TargetFramework>net9.0</TargetFramework> |
||||
|
<RootNamespace /> |
||||
|
<IsPackable>false</IsPackable> |
||||
|
<Configurations>Debug;Release</Configurations> |
||||
|
<Platforms>AnyCPU</Platforms> |
||||
|
</PropertyGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<ProjectReference Include="..\..\framework\exporter\LINGYUN.Abp.Exporter.Pdf.LibreOffice\LINGYUN.Abp.Exporter.Pdf.LibreOffice.csproj" /> |
||||
|
<ProjectReference Include="..\LINGYUN.Abp.Exporter.Pdf.Tests\LINGYUN.Abp.Exporter.Pdf.Tests.csproj" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
</Project> |
||||
@ -0,0 +1,24 @@ |
|||||
|
Microsoft Visual Studio Solution File, Format Version 12.00 |
||||
|
# Visual Studio Version 17 |
||||
|
VisualStudioVersion = 17.5.2.0 |
||||
|
MinimumVisualStudioVersion = 10.0.40219.1 |
||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LINGYUN.Abp.Exporter.Pdf.LibreOffice.Tests", "LINGYUN.Abp.Exporter.Pdf.LibreOffice.Tests.csproj", "{F760B606-3243-2655-8219-F8799FFAE4AF}" |
||||
|
EndProject |
||||
|
Global |
||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution |
||||
|
Debug|Any CPU = Debug|Any CPU |
||||
|
Release|Any CPU = Release|Any CPU |
||||
|
EndGlobalSection |
||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution |
||||
|
{F760B606-3243-2655-8219-F8799FFAE4AF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
||||
|
{F760B606-3243-2655-8219-F8799FFAE4AF}.Debug|Any CPU.Build.0 = Debug|Any CPU |
||||
|
{F760B606-3243-2655-8219-F8799FFAE4AF}.Release|Any CPU.ActiveCfg = Release|Any CPU |
||||
|
{F760B606-3243-2655-8219-F8799FFAE4AF}.Release|Any CPU.Build.0 = Release|Any CPU |
||||
|
EndGlobalSection |
||||
|
GlobalSection(SolutionProperties) = preSolution |
||||
|
HideSolutionNode = FALSE |
||||
|
EndGlobalSection |
||||
|
GlobalSection(ExtensibilityGlobals) = postSolution |
||||
|
SolutionGuid = {E1CB4316-1F23-4B1A-B67C-322A416FD6F5} |
||||
|
EndGlobalSection |
||||
|
EndGlobal |
||||
@ -0,0 +1,6 @@ |
|||||
|
using LINGYUN.Abp.Tests; |
||||
|
|
||||
|
namespace LINGYUN.Abp.Exporter.Pdf.LibreOffice; |
||||
|
public abstract class AbpExporterPdfLibreOfficeTestBase : AbpTestsBase<AbpExporterPdfLibreOfficeTestsModule> |
||||
|
{ |
||||
|
} |
||||
@ -0,0 +1,20 @@ |
|||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Volo.Abp.Autofac; |
||||
|
using Volo.Abp.Modularity; |
||||
|
|
||||
|
namespace LINGYUN.Abp.Exporter.Pdf.LibreOffice; |
||||
|
|
||||
|
[DependsOn( |
||||
|
typeof(AbpExporterPdfLibreOfficeModule), |
||||
|
typeof(AbpExporterPdfTestsModule), |
||||
|
typeof(AbpAutofacModule))] |
||||
|
public class AbpExporterPdfLibreOfficeTestsModule : AbpModule |
||||
|
{ |
||||
|
public override void PreConfigureServices(ServiceConfigurationContext context) |
||||
|
{ |
||||
|
if (!LibreOfficeCommands.IsLibreOffliceInstalled()) |
||||
|
{ |
||||
|
context.Services.AddSingleton<LibreOfficeTestEnvironment>(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,5 @@ |
|||||
|
namespace LINGYUN.Abp.Exporter.Pdf.LibreOffice; |
||||
|
public class AbpExporterPdfLibreOffice_Tests : ExcelToPdfProvider_Tests<AbpExporterPdfLibreOfficeTestsModule> |
||||
|
{ |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,20 @@ |
|||||
|
<Project Sdk="Microsoft.NET.Sdk"> |
||||
|
|
||||
|
<PropertyGroup> |
||||
|
<TargetFramework>net9.0</TargetFramework> |
||||
|
<RootNamespace /> |
||||
|
<IsPackable>false</IsPackable> |
||||
|
<Configurations>Debug;Release</Configurations> |
||||
|
<Platforms>AnyCPU</Platforms> |
||||
|
</PropertyGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<ProjectReference Include="..\..\framework\exporter\LINGYUN.Abp.Exporter.Pdf.SpireLib\LINGYUN.Abp.Exporter.Pdf.SpireLib.csproj" /> |
||||
|
<ProjectReference Include="..\LINGYUN.Abp.Exporter.Pdf.Tests\LINGYUN.Abp.Exporter.Pdf.Tests.csproj" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
</Project> |
||||
@ -0,0 +1,6 @@ |
|||||
|
using LINGYUN.Abp.Tests; |
||||
|
|
||||
|
namespace LINGYUN.Abp.Exporter.Pdf.SpireLib; |
||||
|
public abstract class AbpExporterPdfSpireLibTestBase : AbpTestsBase<AbpExporterPdfSpireLibTestsModule> |
||||
|
{ |
||||
|
} |
||||
@ -0,0 +1,12 @@ |
|||||
|
using Volo.Abp.Autofac; |
||||
|
using Volo.Abp.Modularity; |
||||
|
|
||||
|
namespace LINGYUN.Abp.Exporter.Pdf.SpireLib; |
||||
|
|
||||
|
[DependsOn( |
||||
|
typeof(AbpExporterPdfSpireLibModule), |
||||
|
typeof(AbpExporterPdfTestsModule), |
||||
|
typeof(AbpAutofacModule))] |
||||
|
public class AbpExporterPdfSpireLibTestsModule : AbpModule |
||||
|
{ |
||||
|
} |
||||
@ -0,0 +1,5 @@ |
|||||
|
namespace LINGYUN.Abp.Exporter.Pdf.SpireLib; |
||||
|
public class AbpExporterSpireLibOffice_Tests : ExcelToPdfProvider_Tests<AbpExporterPdfSpireLibTestsModule> |
||||
|
{ |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,25 @@ |
|||||
|
<Project Sdk="Microsoft.NET.Sdk"> |
||||
|
|
||||
|
<PropertyGroup> |
||||
|
<TargetFramework>net9.0</TargetFramework> |
||||
|
<GenerateEmbeddedFilesManifest>true</GenerateEmbeddedFilesManifest> |
||||
|
<IsPackable>false</IsPackable> |
||||
|
<RootNamespace /> |
||||
|
</PropertyGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<None Remove="LINGYUN\Abp\Exporter\Pdf\Resources\test.xlsx" /> |
||||
|
<EmbeddedResource Include="LINGYUN\Abp\Exporter\Pdf\Resources\test.xlsx" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk" /> |
||||
|
<PackageReference Include="Microsoft.Extensions.FileProviders.Embedded" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<ProjectReference Include="..\..\framework\exporter\LINGYUN.Abp.Exporter.Pdf\LINGYUN.Abp.Exporter.Pdf.csproj" /> |
||||
|
<ProjectReference Include="..\LINGYUN.Abp.TestBase\LINGYUN.Abp.TestsBase.csproj" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
</Project> |
||||
@ -0,0 +1,8 @@ |
|||||
|
using Volo.Abp.Modularity; |
||||
|
using Volo.Abp.Testing; |
||||
|
|
||||
|
namespace LINGYUN.Abp.Exporter.Pdf; |
||||
|
public abstract class AbpExporterPdfTestBase<TStartupModule> : AbpIntegratedTest<TStartupModule> |
||||
|
where TStartupModule : IAbpModule |
||||
|
{ |
||||
|
} |
||||
@ -0,0 +1,20 @@ |
|||||
|
using LINGYUN.Abp.Tests; |
||||
|
using Volo.Abp.Modularity; |
||||
|
using Volo.Abp.VirtualFileSystem; |
||||
|
|
||||
|
namespace LINGYUN.Abp.Exporter.Pdf; |
||||
|
|
||||
|
[DependsOn( |
||||
|
typeof(AbpVirtualFileSystemModule), |
||||
|
typeof(AbpExporterPdfModule), |
||||
|
typeof(AbpTestsBaseModule))] |
||||
|
public class AbpExporterPdfTestsModule : AbpModule |
||||
|
{ |
||||
|
public override void ConfigureServices(ServiceConfigurationContext context) |
||||
|
{ |
||||
|
Configure<AbpVirtualFileSystemOptions>(options => |
||||
|
{ |
||||
|
options.FileSets.AddEmbedded<AbpExporterPdfTestsModule>(); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,34 @@ |
|||||
|
using Shouldly; |
||||
|
using System.IO; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.IO; |
||||
|
using Volo.Abp.Modularity; |
||||
|
using Volo.Abp.VirtualFileSystem; |
||||
|
using Xunit; |
||||
|
|
||||
|
namespace LINGYUN.Abp.Exporter.Pdf; |
||||
|
public abstract class ExcelToPdfProvider_Tests<TStartupModule> : AbpExporterPdfTestBase<TStartupModule> |
||||
|
where TStartupModule : IAbpModule |
||||
|
{ |
||||
|
private readonly IExcelToPdfProvider _excelToPdfProvider; |
||||
|
private readonly IVirtualFileProvider _virtualFileProvider; |
||||
|
public ExcelToPdfProvider_Tests() |
||||
|
{ |
||||
|
_excelToPdfProvider = GetRequiredService<IExcelToPdfProvider>(); |
||||
|
_virtualFileProvider = GetRequiredService<IVirtualFileProvider>(); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public async virtual Task Should_Parsed() |
||||
|
{ |
||||
|
var excelFileInfo = _virtualFileProvider.GetFileInfo("/LINGYUN/Abp/Exporter/Pdf/Resources/test.xlsx"); |
||||
|
using (var excelStream = excelFileInfo.CreateReadStream()) |
||||
|
{ |
||||
|
using (var pdfStream = await _excelToPdfProvider.ParseAsync(excelStream)) |
||||
|
{ |
||||
|
pdfStream.Seek(0, System.IO.SeekOrigin.Begin); |
||||
|
pdfStream.Length.ShouldBePositive(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Binary file not shown.
Loading…
Reference in new issue