using Aspose.Words;
using Aspose.Words.Saving;
using System.IO.Compression;
namespace ConsoleApp4
{
internal class Program
{
static void Main(string[] args)
{
var html = GetHtml();
using var memoryStream = new MemoryStream();
using var zipArchive = new ZipArchive(memoryStream, ZipArchiveMode.Create, true);
var now = DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss");
for (int i = 0; i
/// 获取html代码
///
///
static string GetHtml()
{
var htmlData = @"
Aspose测试
table {
border: 1px solid #000;
}
| 姓名 | 年龄 |
|---|---|
| 小明 | 20 |
| 小红 | 22 |
| 小华 | 18 |
“;
return htmlData;
}
static byte[] Html2Word(string htmlContent)
{
//如果有正版授权请写入
//var memoryStream = new MemoryStream(Convert.FromBase64String(“”));
//var license = new Aspose.Words.License();
//license.SetLicense(memoryStream);
var doc = new Aspose.Words.Document();
doc.RemoveAllChildren();
Aspose.Words.DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertHtml(htmlContent);
//var now = DateTime.Now.ToString(“yyyy_MM_dd_HH_mm_ss”);
//var docPath = now + “.docx”;
//doc.Save(docPath);
var resultMemoryStream = new MemoryStream();
doc.Save(resultMemoryStream, SaveOptions.CreateSaveOptions(SaveFormat.Docx));
return resultMemoryStream.ToArray();
}
}
}


安卓手机解压缩出现损坏的问题
方案1 使用SharpCompress
using Aspose.Words;
using Aspose.Words.Saving;
using SharpCompress.Archives.Zip;
using System;
using System.IO;
namespace ZipStu02
{
internal class Program
{
static void Main(string[] args)
{
var html = GetHtml();
var now = DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss");
var archive = ZipArchive.Create();
for (int i = 0; i
方案2 使用aspose.zip
//var license = new Aspose.Zip.License();
//license.SetLicense("Aspose.Total.lic");
var html = GetHtml();
//Html2Word(html);
var now = DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss");
var archive = new Archive();
for (int i = 0; i
参考
https://docs.aspose.com/zip/net/
https://github.com/adamhathcock/sharpcompress/wiki/API-Examples
到此这篇关于asp.net core实现在线生成多个文件将多个文件打包为zip返回的文章就介绍到这了,更多相关asp.net core在线生成多个文件内容请搜索IT俱乐部以前的文章或继续浏览下面的相关文章希望大家以后多多支持IT俱乐部!
