using Aspose.Words;
|
using SkiaSharp;
|
using System.Drawing;
|
using Yw.DiagramFile;
|
using Yw.DiagramFile.Image;
|
|
namespace HStation.ReportFile
|
{
|
public class SimulationWordReportHelper
|
{
|
private Aspose.Words.DocumentBuilder _builder = null;
|
|
public SimulationWordReportHelper(Aspose.Words.DocumentBuilder builder)
|
{
|
this._builder = builder;
|
}
|
|
/// <summary>
|
///
|
/// 设置字体 默认宋体 10 黑色 加粗
|
/// </summary>
|
/// <param name="fontalignment">对齐方式</param>
|
public void SetFont(Aspose.Words.ParagraphAlignment fontalignment)
|
{
|
_builder.ParagraphFormat.Alignment = fontalignment;
|
_builder.SetBuilderFont(_font, _fontSize, _fontcolor, _isBlod);
|
}
|
|
/// <summary>
|
/// 设置字体 默认左对齐 宋体 黑色 加粗
|
/// </summary>
|
/// <param name="fontSize">字体大小</param>
|
public void SetFont(int fontSize)
|
{
|
_builder.ParagraphFormat.Alignment = _fontalignment;
|
_builder.SetBuilderFont(_font, fontSize, _fontcolor, _isBlod);
|
}
|
|
/// <summary>
|
/// 设置字体 默认左对齐 宋体 10 加粗
|
/// </summary>
|
/// <param name="fontcolor">字体颜色</param>
|
public void SetFont(Color fontcolor)
|
{
|
_builder.ParagraphFormat.Alignment = _fontalignment;
|
_builder.SetBuilderFont(_font, _fontSize, fontcolor, _isBlod);
|
}
|
|
/// <summary>
|
/// 设置字体 默认左对齐 宋体 10 黑色
|
/// </summary>
|
/// <param name="isBlod">是否加粗</param>
|
public void SetFont(bool isBlod)
|
{
|
_builder.ParagraphFormat.Alignment = _fontalignment;
|
_builder.SetBuilderFont(_font, _fontSize, _fontcolor, isBlod);
|
}
|
|
/// <summary>
|
/// 设置字体
|
/// </summary>
|
/// <param name="fontalignment">对齐方式</param>
|
/// <param name="font">字体</param>
|
/// <param name="fontSize">字体大小</param>
|
/// <param name="fontcolor">字体颜色</param>
|
/// <param name="isBlod">是否加粗</param>
|
public void SetFont(Aspose.Words.ParagraphAlignment fontalignment, string font, int fontSize, Color fontcolor, bool isBlod)
|
{
|
_builder.ParagraphFormat.Alignment = fontalignment;
|
_builder.SetBuilderFont(font, fontSize, fontcolor, isBlod);
|
}
|
|
/// <summary>
|
/// 垂直合并单元格的方式 默认不合并
|
/// </summary>
|
private Aspose.Words.Tables.CellMerge _verticalMerge = Aspose.Words.Tables.CellMerge.None;
|
|
/// <summary>
|
/// 水平合并单元格的方式 默认不合并
|
/// </summary>
|
private Aspose.Words.Tables.CellMerge _horizontalMerge = Aspose.Words.Tables.CellMerge.None;
|
|
/// <summary>
|
/// 单元格边框格式 默认单线
|
/// </summary>
|
private LineStyle _lineStyle = LineStyle.Single;
|
|
/// <summary>
|
/// 单元格对齐方式 默认居中
|
/// </summary>
|
private ParagraphAlignment _alignment = ParagraphAlignment.Center;
|
|
/// <summary>
|
/// 单元格上边框样式
|
/// </summary>
|
private LineStyle _top = LineStyle.Single;
|
|
/// <summary>
|
/// 单元格下边框样式
|
/// </summary>
|
private LineStyle _bottom = LineStyle.Single;
|
|
/// <summary>
|
/// 单元格左边框样式
|
/// </summary>
|
private LineStyle _left = LineStyle.Single;
|
|
/// <summary>
|
/// 单元格右边框样式
|
/// </summary>
|
private LineStyle _right = LineStyle.Single;
|
|
/// <summary>
|
/// 单元格宽度 默认-1 自动计算
|
/// </summary>
|
private double _width = -1;
|
|
/// <summary>
|
/// 是否加粗 默认不加粗
|
/// </summary>
|
private bool _isBold = false;
|
|
/// <summary>
|
/// 背景色的RGB值,格式为"R,G,B"
|
/// </summary>
|
private string _rgbstr = "";
|
|
/// <summary>
|
/// 文本是否斜体 默认否
|
/// </summary>
|
private bool _isItalic = false;
|
|
/// <summary>
|
/// 字体 默认宋体
|
/// </summary>
|
private string _font = "宋体";
|
|
/// <summary>
|
/// 字体大小 默认10
|
/// </summary>
|
private int _fontSize = 10;
|
|
/// <summary>
|
/// 字体是否加粗 默认加粗
|
/// </summary>
|
private bool _isBlod = false;
|
|
/// <summary>
|
/// 字体颜色 默认黑
|
/// </summary>
|
private Color _fontcolor = Color.Black;
|
|
/// <summary>
|
/// 文字对齐方式 默认左
|
/// </summary>
|
private Aspose.Words.ParagraphAlignment _fontalignment = ParagraphAlignment.Left;
|
|
public Aspose.Words.ParagraphAlignment fontalignment
|
{
|
get { return _fontalignment; }
|
set { _fontalignment = value; }
|
}
|
|
public Color fontcolor
|
{
|
get { return _fontcolor; }
|
set { _fontcolor = value; }
|
}
|
|
public bool isblod
|
{
|
get { return _isBlod; }
|
set { _isBlod = value; }
|
}
|
|
public int fontsize
|
{
|
get { return _fontSize; }
|
set { _fontSize = value; }
|
}
|
|
public string font
|
{
|
get { return _font; }
|
set { _font = value; }
|
}
|
|
public Aspose.Words.Tables.CellMerge verticalMerge
|
{
|
get { return _verticalMerge; }
|
set { _verticalMerge = value; }
|
}
|
|
public Aspose.Words.Tables.CellMerge horizontalMerge
|
{
|
get { return _horizontalMerge; }
|
set { _horizontalMerge = value; }
|
}
|
|
public LineStyle lineStyle
|
{
|
get { return _lineStyle; }
|
set { _lineStyle = value; }
|
}
|
|
public ParagraphAlignment alignment
|
{
|
get { return _alignment; }
|
set { _alignment = value; }
|
}
|
|
public LineStyle top
|
{
|
get { return _top; }
|
set { _top = value; }
|
}
|
|
public LineStyle bottom
|
{
|
get { return _bottom; }
|
set { _bottom = value; }
|
}
|
|
public LineStyle left
|
{
|
get { return _left; }
|
set { _left = value; }
|
}
|
|
public LineStyle right
|
{
|
get { return _right; }
|
set { _right = value; }
|
}
|
|
public double width
|
{
|
get { return _width; }
|
set { _width = value; }
|
}
|
|
public bool isBold
|
{
|
get { return _isBold; }
|
set { _isBold = value; }
|
}
|
|
public string rgbstr
|
{
|
get { return _rgbstr; }
|
set { _rgbstr = value; }
|
}
|
|
public bool isItalic
|
{
|
get { return _isItalic; }
|
set { _isItalic = value; }
|
}
|
|
/// <summary>
|
/// 构建文字
|
/// </summary>
|
/// <param name="content"></param>
|
public void structureLeft20Text(string content)
|
{
|
_builder.ParagraphFormat.Alignment = _fontalignment;
|
_builder.SetBuilderFont(_font, _fontSize, _fontcolor, _isBlod);
|
_builder.ParagraphFormat.SpaceBefore = 5;
|
_builder.ParagraphFormat.FirstLineIndent = 30;
|
_builder.Writeln(content);
|
}
|
|
/// <summary>
|
/// 添加空行
|
/// </summary>
|
/// <param name="content"></param>
|
public void AddBlankLine()
|
{
|
_builder.Writeln();
|
}
|
|
/// <summary>
|
/// 构建文字
|
/// </summary>
|
/// <param name="content"></param>
|
public void structureText(string content)
|
{
|
_builder.ParagraphFormat.Alignment = _fontalignment;
|
_builder.SetBuilderFont(_font, _fontSize, _fontcolor, _isBlod);
|
_builder.ParagraphFormat.SpaceBefore = 5;
|
_builder.ParagraphFormat.LeftIndent = 0;
|
_builder.Writeln(content);
|
}
|
|
/// <summary>
|
/// 构建图片
|
/// </summary>
|
/// <param name="content">文字内容</param>
|
/// <param name="address">图片地址</param>
|
public void structureTextAndImage(string address, int height, int wide)
|
{
|
_builder.ParagraphFormat.Alignment = _fontalignment;
|
_builder.SetBuilderFont(_font, _fontSize, _fontcolor, _isBlod);
|
if (!System.IO.File.Exists(address))
|
{
|
return;
|
}
|
_builder.InsertImage(address, wide, height);
|
_builder.Writeln("");
|
}
|
|
/// <summary>
|
/// 构建泵曲线图片
|
/// </summary>
|
/// <param name="content">文字内容</param>
|
/// <param name="address">图片地址</param>
|
public void BuildingPumpCurvePicture(PumpChartViewModel pumpChartViewModel, double wide, double height)
|
{
|
if (pumpChartViewModel == null)
|
return;
|
var pumpDiagram = new PumpChart();
|
var bitmap = pumpDiagram.Create(pumpChartViewModel);
|
_builder.ParagraphFormat.Alignment = _fontalignment;
|
_builder.SetBuilderFont(_font, _fontSize, _fontcolor, _isBlod);
|
if (bitmap == null)
|
{
|
return;
|
}
|
_builder.InsertImage(bitmap, wide, height);
|
_builder.Writeln("");
|
}
|
|
/// <summary>
|
/// 构建图片 (同一行多个图片)
|
/// </summary>
|
/// <param name="addresses">图片地址列表</param>
|
/// <param name="height">图片高度</param>
|
/// <param name="width">图片宽度</param>
|
/// <param name="spacing">图片之间的间距</param>
|
public void structureImagesInRow(List<string> addresses, int height, int width)
|
{
|
_builder.ParagraphFormat.Alignment = _fontalignment;
|
_builder.SetBuilderFont(_font, _fontSize, _fontcolor, _isBlod);
|
|
foreach (var address in addresses)
|
{
|
if (!System.IO.File.Exists(address))
|
{
|
continue; // 如果文件不存在,则跳过该图片
|
}
|
|
_builder.InsertImage(address, width, height);
|
}
|
|
_builder.Writeln(""); // 在所有图片插入后添加一个换行
|
}
|
|
/* /// <summary>
|
/// 构建图片
|
/// </summary>
|
/// <param name="content">文字内容</param>
|
/// <param name="BitMap">图片地址</param>
|
public void structureTextAndImage(Bitmap BitMap, int height, int wide)
|
{
|
using (var stream = new MemoryStream())
|
{
|
// 将System.Drawing.Bitmap保存到内存流中
|
BitMap.Save(stream, ImageFormat.Png);
|
stream.Position = 0;
|
// 使用SKManagedStream从内存流中解码出SKBitmap
|
using (var skManagedStream = new SKManagedStream(stream))
|
{
|
var skBitmap = SKBitmap.Decode(skManagedStream);
|
_builder.ParagraphFormat.Alignment = _fontalignment;
|
_builder.SetBuilderFont(_font, _fontSize, _fontcolor, _isBlod);
|
_builder.InsertImage(skBitmap, wide, height);
|
_builder.Writeln("");
|
}
|
}
|
}
|
|
*/ /// <summary>
|
|
/// 构建图片
|
/// </summary>
|
/// <param name="address"></param>
|
public void structureTextAndImage(string address)
|
{
|
_builder.ParagraphFormat.Alignment = _fontalignment;
|
_builder.SetBuilderFont(_font, _fontSize, _fontcolor, _isBlod);
|
if (!System.IO.File.Exists(address))
|
{
|
return;
|
}
|
_builder.InsertImage(address);
|
_builder.Writeln("");
|
}
|
|
/// <summary>
|
/// 创建单元格(带背景颜色)
|
/// </summary>
|
public void structureCell(string content)
|
{
|
_builder.ParagraphFormat.FirstLineIndent = 0;
|
_builder.ParagraphFormat.LeftIndent = 2;
|
var cell = _builder.InsertCell();
|
//_builder.InsertParagraph(); // 添加一个新段落
|
//_builder.ParagraphFormat.Alignment = ParagraphAlignment.Center; // 设置段落垂直居中
|
_builder.CellFormat.VerticalMerge = _verticalMerge;
|
_builder.CellFormat.HorizontalMerge = _horizontalMerge;
|
//builder.CellFormat.Borders.LineStyle = lineStyle;
|
_builder.CellFormat.Borders[BorderType.Bottom].LineStyle = _bottom;
|
_builder.CellFormat.TopPadding = 1;
|
_builder.CellFormat.Borders[BorderType.Top].LineStyle = _top;
|
_builder.CellFormat.Borders[BorderType.Left].LineStyle = _left;
|
_builder.CellFormat.Borders[BorderType.Right].LineStyle = _right;
|
_builder.ParagraphFormat.Alignment = _alignment;
|
_builder.CellFormat.VerticalAlignment = Aspose.Words.Tables.CellVerticalAlignment.Center;
|
_builder.CellFormat.Width = _width;
|
//builder.CellFormat.Borders.LineStyle = lineStyle;
|
_builder.Bold = _isBold;
|
_builder.Italic = _isItalic;
|
//builder.CellFormat.Shading.ForegroundPatternColor = System.Drawing.Color.FromArgb(255, 255, 255);//设置单元格背景色
|
if (!string.IsNullOrEmpty(_rgbstr))
|
{
|
var rgblist = _rgbstr.Split(',').ToList();
|
if (rgblist.Count == 3)
|
_builder.CellFormat.Shading.BackgroundPatternColor = System.Drawing.Color.FromArgb(Convert.ToInt32(rgblist[0]), Convert.ToInt32(rgblist[1]), Convert.ToInt32(rgblist[2]));//设置单元格背景色
|
}
|
|
//builder.CellFormat.Shading.BackgroundPatternColor = System.Drawing.Color.FromArgb(red, green, blue);//设置单元格背景色
|
//builder.Underline = isUnderline;
|
if (content == null)
|
{
|
_builder.Write(""); // 在新段落中写入内容
|
return;
|
}
|
|
_builder.Write(content); // 在新段落中写入内容
|
//cell.FirstParagraph.Remove();
|
}
|
}
|
}
|