using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using System;
using System.IO;
using System.Net;
using System.Windows.Forms;
namespace HltkQuotationApp.Extend
{
public class HdhCmsExcelExportTest
{
public static void HdhCmsExportExcel()
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.FileName = "HdhCms" + DateTime.Now.ToString("yyyyMMddhhmmssfff") + ".xlsx";
if (sfd.ShowDialog().Equals(DialogResult.OK))
{
using (var fs = new FileStream(sfd.FileName, FileMode.Create))
{
IWorkbook HdhCmsWorkBok = new XSSFWorkbook();
ISheet sheet = HdhCmsWorkBok.CreateSheet("文章报表");
// 创建标题行(合并单元格)
IRow titleRow = sheet.CreateRow(0);
titleRow.CreateCell(0).SetCellValue("带段落的复杂报表,来自于Hdhcms的案例");
sheet.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress(0, 0, 0, 3));
// 添加文章段落(自动换行)
IRow contentRow = sheet.CreateRow(2);
ICell paragraphCell = contentRow.CreateCell(0);
paragraphCell.CellStyle = HdhCmsWorkBok.CreateCellStyle();
paragraphCell.CellStyle.WrapText = true;
string longText = "HdhCMS是一款轻量级的建站管理系统,CMS支持网站建设与客户关系管理,是一款综合性的建站与内容管理系统(CMS)。 系统集成了微信公众号(订阅号、服务号)接入,可以在后台轻松设置微信自定义菜单、自动回复;有开发小程序API接口 ,可以很轻松开发小程序展示型网站。这是第一段文字内容...\n\nHDHCMS自2025年3月13日起除部分高级功能外免费使用。我们承诺HDHCMS永远不追究版权问题。下载带模板的HDHCMS系统直接运行。HDHCMS运行环境:IIS7.0及以上+SQLITE/MSSQL2008及以上+.NET4.8。全新制作须修改hdhapp.config中默认的数据库名称,或删除原有系统数据库。再运行后台地址或主域名,系统会自动建库建表,看到登录地址后即表示系统配置完成。全新建站支行地址:http://绑定域名,后台管理登录地址:http://绑定域名/admin。这是第二段文字内容...";
paragraphCell.SetCellValue(longText);
// 设置行高适应内容
//contentRow.HeightInPoints = 100;
// 添加本地图片
//byte[] imageBytes = File.ReadAllBytes("E:\\aa\\hdhcms.png");
//添加网络图片
WebClient client = new WebClient();
byte[] imageBytes = client.DownloadData("http://www.hdhcms.com/upfiles/images/20230531/202305312138347358.png");
int pictureIdx = HdhCmsWorkBok.AddPicture(imageBytes, PictureType.PNG);
IDrawing drawing = sheet.CreateDrawingPatriarch();
IClientAnchor anchor = drawing.CreateAnchor(0, 0, 0, 0, 4, 2, 16, 15);
drawing.CreatePicture(anchor, pictureIdx);
HdhCmsWorkBok.Write(fs);
}
}
}
}
}
查看更多关于C#导出复杂图文混合类型EXCEL文档源码的详细内容...