using IStation.Application.Report.Helper;
using IStation.Model;
using IStation.Model.Eta;
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.rtf.headerfooter;
using Microsoft.AspNetCore.Http;
using System.Text;
namespace IStation.Application
{
///
///
///
public class Eta_Month_ReportPdf
{
#region 属性
Document _document;
PdfWriter _writer;
BaseFont _baseFont_general = null;//常规字体
BaseFont _baseFont_spec_char;//特殊字符字体
Font _fontSize8;
Font _fontSize9_bold;
Font _fontSize13_bold;
Font _fontSize11;
int _currentPage = 0;
///
/// 生成报表
///
/// 泵站信息
/// 汇总
/// 机泵管路列表
/// 机泵信息列表
/// 路径
///
public bool Create4Stream(Station station, List pipeList, List list,string path)
{
InitialFont();
//初始化标题中的LOGO图片
InitialTitleLogoImage();
MemoryStream strem = new MemoryStream();
_document = new Document(PageSize.A4);
_document.SetMargins(-40, -40, 40, 40);
_writer = PdfWriter.GetInstance(_document, new FileStream(path, FileMode.Create));
_writer.PageEvent = new CreatHeaderAndFoot();
CreatestationInfoPage(station, pipeList, list);//产品信息
_document.Close();
return true;
}
//字体
private void InitialFont()
{
string fileTtc_simsun = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "fonts\\simsun.ttc");
if (!File.Exists(fileTtc_simsun))
{
if (File.Exists(@"C:\Windows\Fonts\simsun.ttc"))
{
fileTtc_simsun = @"C:\Windows\Fonts\simsun.ttc";
}
else
{
if (File.Exists(@"C:\Windows\Fonts\simsunb.ttc"))
{
fileTtc_simsun = @"C:\Windows\Fonts\simsunb.ttc";
}
}
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
_baseFont_spec_char = BaseFont.CreateFont(fileTtc_simsun + ",1", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);//读取ttc字体
//BaseFont.CreateFont 的第一个参数,在字体文件后不一定需要跟上“,1”。
//这取决于使用的字体文件是否支持多字体。例如simsun.ttc 包含了“宋体”和“新宋体”两套字体,
//那么如果要使用这个字体文件,就必须指明使用哪一套字体,序号从0开始。
//但如果使用的字体文件只有一套字体,则一定不能加“,0”。否则,无论是多加还是少加,都会报错。
//要想知道字体文件是否是多套字体,只需双击打开字体文件,如果有导航的>>和<<按钮,则是有多套字体,否则就不是。
//TTC是几个TTF合成的字库,安装后字体列表中会看到两个以上的字体。
}
_fontSize8 = new Font(_baseFont_spec_char, 8);
_fontSize9_bold = new Font(_baseFont_spec_char, 9, Font.BOLD);
_fontSize13_bold = new Font(_baseFont_spec_char, 13, Font.BOLD);
_fontSize11 = new Font(_baseFont_spec_char, 11);
}
#region LOGO图片
System.Drawing.Image _imgTitleCorpLogo = null;//表头的LOGO
///
///
///
public void InitialTitleLogoImage()
{
//如果Data文件夹下有就优先
string strLogoFullPath = string.Format("{0}\\SelectReportTitleLogo.png", 1);
if (File.Exists(strLogoFullPath))
{
_imgTitleCorpLogo = System.Drawing.Image.FromFile(strLogoFullPath);
return;
}
strLogoFullPath = string.Format("{0}\\CorpLogo.png", 1);
if (File.Exists(strLogoFullPath))
{
_imgTitleCorpLogo = System.Drawing.Image.FromFile(strLogoFullPath);
return;
}
//没有就搜索Infomation文件夹
strLogoFullPath = string.Format("{0}Infomation\\CorpLogo.png", AppDomain.CurrentDomain.BaseDirectory);
if (File.Exists(strLogoFullPath))
{
_imgTitleCorpLogo = System.Drawing.Image.FromFile(strLogoFullPath);
}
}
#endregion
///
///
///
///
///
///
///
public void CreatestationInfoPage(Station station, List pipeList, List list)
{
_document.Open();
_document.NewPage();
_currentPage++;
CreateHaderTable();
int runcout = 0;
double qt = 0;
double dt = 0;
foreach (var item in list)
{
if (item.RunTime > 0)
runcout = runcout + 1;
if (item.Qt > 0)
qt += item.Qt;
if (item.Dt > 0)
dt += item.Dt;
}
string Qt = "";
if (qt < 10)
Qt = Math.Round((double)qt, 3).ToString();
if (10 < qt && qt < 1000)
Qt = Math.Round((double)qt, 2).ToString();
if (qt > 1000)
Qt = Math.Round((double)qt, 1).ToString();
string Dt = "";
if (dt < 10)
Dt = Math.Round((double)dt, 3).ToString();
if (10 < dt && dt < 1000)
Dt = Math.Round((double)dt, 2).ToString();
if (dt > 1000)
Dt = Math.Round((double)dt, 1).ToString();
CreatestationTable(station, runcout, Qt, Dt);
CreatestationInfoTable(pipeList, list, station.ID);
PdfPTable table1 = new PdfPTable(3);
float[] widths = { 80, 140, 300 };
table1.SetWidths(widths);
PdfPCell cell = new PdfPCell();
cell = CreateCell2("设备状态:" + station.UseStatus, _fontSize8, 1, 1);
table1.AddCell(cell);
_document.Add(table1);
CreatePropTable();
}
///
///
///
public void CreatePropTable()
{
List _allPartPropList = new List();
_allPartPropList.Add(10);
PdfPTable table = new PdfPTable(2);
float[] widths = { 300, 300 };
table.SetWidths(widths);
PdfPCell cell = new PdfPCell();
int endIndex = 0;
cell.DisableBorderSide(8);
cell.AddElement(PropertyTable(38, 0, out endIndex));
table.AddCell(cell);
if (endIndex < _allPartPropList.Count && endIndex > -1)
{
cell = new PdfPCell();
cell.DisableBorderSide(4);
cell.AddElement(PropertyTable(38, endIndex, out endIndex));
table.AddCell(cell);
}
_document.Add(table);
}
///
///
///
///
///
///
///
public PdfPTable PropertyTable(int displayRow, int startIndex, out int endIndex)
{
PdfPTable table = new PdfPTable(2);
float[] widths = { 300, 300 };
table.SetWidths(widths);
PdfPCell cell = new PdfPCell();
int row = 0;//记录循环的行数
string groupName = string.Empty;
if (row != 0)
{
cell = CreateCell2("", _fontSize9_bold, 2, 1, 10, 15);
table.AddCell(cell);
row++;
}
groupName = "名称";
cell = CreateCell1("名称", _fontSize9_bold, 2, 1, 13, 15);
table.AddCell(cell);
row++;
cell = CreateCell2("名称", _fontSize8, 1, 1, 13, 0, Element.ALIGN_LEFT, Element.ALIGN_LEFT, true);
cell.PaddingLeft = 8;
table.AddCell(cell);
cell = CreateCell2("名称", _fontSize8, 1, 1, 13, 0);
cell.PaddingLeft = 8;
table.AddCell(cell);
row++;
endIndex = -1;
return table;
}
private PdfPCell AddPicture(System.Drawing.Image image,
int colspan, int rowspan,
float cellHeight,
int BorderWidthLeft = -1, int BorderWidthRight = -1,
int BorderWidthTop = -1, int BorderWidthBottom = -1, float fixHeight = -1)
{
if (image == null)
return null;
PdfPCell cell = new PdfPCell();
cell.Colspan = colspan;
cell.Rowspan = rowspan;
cell.MinimumHeight = cellHeight;
cell.FixedHeight = cellHeight;
cell.VerticalAlignment = Element.ALIGN_MIDDLE;
cell.HorizontalAlignment = Element.ALIGN_CENTER;
if (BorderWidthLeft >= 0)
cell.BorderWidthLeft = BorderWidthLeft;
if (BorderWidthLeft >= 0)
cell.BorderWidthRight = BorderWidthRight;
if (BorderWidthTop >= 0)
cell.BorderWidthTop = BorderWidthTop;
if (BorderWidthBottom >= 0)
cell.BorderWidthBottom = BorderWidthBottom;
if (fixHeight > 0)
cell.FixedHeight = fixHeight;
while (image.Width > 1800)
{
image = image.GetThumbnailImage(Convert.ToInt32(image.Width * 0.9), Convert.ToInt32(image.Height * 0.9), () => { return false; }, IntPtr.Zero);
}
var imgTextSharp = Image.GetInstance(image, BaseColor.White);
imgTextSharp.Alignment = Element.ALIGN_MIDDLE;
cell.Image = imgTextSharp;
return cell;
}
///
/// 表头
///
public void CreateHaderTable()
{
PdfPTable table = new PdfPTable(1);
PdfPCell cell = new PdfPCell();
cell = CreateCell2("泵站能效日报表", _fontSize13_bold, 1, 1, 50, 0, Element.ALIGN_CENTER);
cell.HorizontalAlignment = Element.ALIGN_CENTER;//水平居中
cell.VerticalAlignment = Element.ALIGN_MIDDLE;//垂直居中
table.AddCell(cell);
_document.Add(table);
}
///
/// 设备信息
///
//
public void CreatestationTable(Station station, int cout, string qt, string dt)
{
PdfPTable table = new PdfPTable(4);
PdfPCell cell = new PdfPCell();
float[] widths = new float[] { 60, 60, 60, 60 };
cell = CreateCell2("泵站信息", _fontSize11, 4, 1, 40, 0, Element.ALIGN_CENTER);
table.AddCell(cell);
cell = CreateCell2("泵站名称", _fontSize11, 1, 1, 40, 0, Element.ALIGN_CENTER);
table.AddCell(cell);
cell = CreateCell2(station.Name, _fontSize11, 1, 1, 40, 0, Element.ALIGN_CENTER);
table.AddCell(cell);
cell = CreateCell2("运行数量" + " (台)", _fontSize11, 1, 1, 40, 0, Element.ALIGN_CENTER);
table.AddCell(cell);
cell = CreateCell2(cout.ToString(), _fontSize11, 1, 1, 40, 0, Element.ALIGN_CENTER);
table.AddCell(cell);
cell = CreateCell2("总电能" + " (A)", _fontSize11, 1, 1, 40, 0, Element.ALIGN_CENTER);
table.AddCell(cell);
cell = CreateCell2(dt, _fontSize11, 1, 1, 40, 0, Element.ALIGN_CENTER);
table.AddCell(cell);
cell = CreateCell2("总流量" + " (m³)", _fontSize11, 1, 1, 40, 0, Element.ALIGN_CENTER);
table.AddCell(cell);
cell = CreateCell2(qt, _fontSize11, 1, 1, 40, 0, Element.ALIGN_CENTER);
table.AddCell(cell);
cell = CreateCell2("报告日期", _fontSize11, 1, 1, 40, 0, Element.ALIGN_CENTER);
table.AddCell(cell);
cell = CreateCell2("", _fontSize11, 1, 1, 40, 0, Element.ALIGN_CENTER);
table.AddCell(cell);
cell = CreateCell2("使用状态", _fontSize11, 1, 1, 40, 0, Element.ALIGN_CENTER);
table.AddCell(cell);
cell = CreateCell2(station.UseStatus == eUseStatus.Enable ? "使用中" : "已停用", _fontSize11, 1, 1, 40, 0, Element.ALIGN_CENTER);
if (station.UseStatus == eUseStatus.Enable)
cell.BackgroundColor = BaseColor.Green;
if (station.UseStatus == eUseStatus.Disable)
cell.BackgroundColor = BaseColor.Gray;
table.AddCell(cell);
cell = CreateCell2("地址", _fontSize11, 1, 1, 40, 0, Element.ALIGN_CENTER);
table.AddCell(cell);
cell = CreateCell2(station.Address, _fontSize11, 3, 1, 40, 0, Element.ALIGN_CENTER);
table.AddCell(cell);
table.SetWidths(widths);
_document.Add(table);
}
///
/// 生成机泵列表
///
/// 机泵列表
public void CreatestationInfoTable(List pipeList, List list, long stationID)
{
PdfPTable table = new PdfPTable(5);
PdfPCell cell = new PdfPCell();
float[] widths = new float[] { 60, 60, 60, 60, 60 };
var ProductList = new Service.Product().GetByCorpID(list.FirstOrDefault().CorpID);
cell = CreateCell2("能效信息", _fontSize11, 5, 1, 40, 0, Element.ALIGN_CENTER);
table.AddCell(cell);
var seviceEnginePump = new Service.Product();
foreach (var item in list)
{
var EnginePumpLine = pipeList?.Find(x => x.ID == item.ObjectID);
var EnginePump = ProductList.Find(x => x.BelongID == stationID && x.Name == EnginePumpLine.Name);
var Pump = seviceEnginePump.GetChildPumpByEnginePumpID(EnginePump.CorpID, EnginePump.ID);
var Motor = seviceEnginePump.GetChildMotorByEnginePumpID(EnginePump.CorpID, EnginePump.ID);
cell = CreateCell2(EnginePump?.Name, _fontSize11, 1, 4, 40, 0, Element.ALIGN_CENTER);
table.AddCell(cell);
cell = CreateCell2("状态", _fontSize11, 1, 1, 40, 0, Element.ALIGN_CENTER);
table.AddCell(cell);
int usetatus = 0;
if (item.UWPavg < 1)
usetatus = 0;
if (item.UWPavg > 0)
usetatus = 1;
cell = CreateCell2(usetatus == 1 ? "开启" : "未开启", _fontSize11, 1, 1, 40, 0, Element.ALIGN_CENTER);
if (usetatus == 1)
cell.BackgroundColor = BaseColor.Green;
if (usetatus == 0)
cell.BackgroundColor = BaseColor.Gray;
table.AddCell(cell);
cell = CreateCell2("运行时间" + " (h)", _fontSize11, 1, 1, 40, 0, Element.ALIGN_CENTER);
table.AddCell(cell);
var runtime = Math.Round((decimal)item.RunTime / 3600, 1);
cell = CreateCell2(runtime < 1 ? @"/" : runtime.ToString(), _fontSize11, 1, 1, 40, 0, Element.ALIGN_CENTER);
table.AddCell(cell);
cell = CreateCell2("泵型号", _fontSize11, 1, 1, 40, 0, Element.ALIGN_CENTER);
table.AddCell(cell);
cell = CreateCell2(Pump?.Code, _fontSize11, 1, 1, 40, 0, Element.ALIGN_CENTER);
table.AddCell(cell);
cell = CreateCell2("电机型号", _fontSize11, 1, 1, 40, 0, Element.ALIGN_CENTER);
table.AddCell(cell);
cell = CreateCell2(Motor?.Code, _fontSize11, 1, 1, 40, 0, Element.ALIGN_CENTER);
table.AddCell(cell);
cell = CreateCell2("总电能" + " (A)", _fontSize11, 1, 1, 40, 0, Element.ALIGN_CENTER);
table.AddCell(cell);
string Dt = "";
if (item.Dt < 10)
Dt = Math.Round((double)item.Dt, 3).ToString();
if (10 < item.Dt && item.Dt < 1000)
Dt = Math.Round((double)item.Dt, 2).ToString();
if (item.Dt > 1000)
Dt = Math.Round((double)item.Dt, 1).ToString();
cell = CreateCell2(item.Dt < 1 ? @"/" : Dt, _fontSize11, 1, 1, 40, 0, Element.ALIGN_CENTER);
table.AddCell(cell);
cell = CreateCell2("总流量" + " (m³)", _fontSize11, 1, 1, 40, 0, Element.ALIGN_CENTER);
table.AddCell(cell);
string Qt = "";
if (item.Qt < 10)
Qt = Math.Round((double)item.Qt, 3).ToString();
if (10 < item.Qt && item.Qt < 1000)
Qt = Math.Round((double)item.Qt, 2).ToString();
if (item.Qt > 1000)
Qt = Math.Round((double)item.Qt, 1).ToString();
cell = CreateCell2(item.Qt < 1 ? @"/" : Qt, _fontSize11, 1, 1, 40, 0, Element.ALIGN_CENTER);
table.AddCell(cell);
cell = CreateCell2("平均单位能耗" + " \n(kw·h)", _fontSize11, 1, 1, 40, 0, Element.ALIGN_CENTER);
table.AddCell(cell);
string UWPavg = "";
if (item.UWPavg < 10)
UWPavg = Math.Round((double)item.UWPavg, 3).ToString();
if (10 < item.UWPavg && item.UWPavg < 1000)
UWPavg = Math.Round((double)item.UWPavg, 2).ToString();
if (item.UWPavg > 1000)
UWPavg = Math.Round((double)item.UWPavg, 1).ToString();
cell = CreateCell2(item.UWPavg < 1 ? @"/" : UWPavg, _fontSize11, 1, 1, 40, 0, Element.ALIGN_CENTER);
table.AddCell(cell);
cell = CreateCell2("平均千吨能耗" + " \n(kw·h)", _fontSize11, 1, 1, 40, 0, Element.ALIGN_CENTER);
table.AddCell(cell);
string wpavg = "";
if (item.WPavg < 10)
wpavg = Math.Round((double)item.WPavg, 3).ToString();
if (10 < item.WPavg && item.WPavg < 1000)
wpavg = Math.Round((double)item.WPavg, 2).ToString();
if (item.WPavg > 1000)
wpavg = Math.Round((double)item.WPavg, 1).ToString();
cell = CreateCell2(item.WPavg < 1 ? @"/" : wpavg, _fontSize11, 1, 1, 40, 0, Element.ALIGN_CENTER);
table.AddCell(cell);
}
table.SetWidths(widths);
_document.Add(table);
}
///
///
///
///
public void CreateEndTable(EtaMultiRealRecordPure item)
{
PdfPTable table = new PdfPTable(4);
PdfPCell cell = new PdfPCell();
float[] widths = new float[] { 60, 60, 60, 60 };
cell = CreateCell2("※※※※※※※※※※※※※※分割线※※※※※※※※※※※※※※※※", _fontSize11, 4, 1, 30, 0, Element.ALIGN_CENTER);
table.AddCell(cell);
cell = CreateCell2("分析信息", _fontSize11, 4, 1, 30, 0, Element.ALIGN_CENTER);
table.AddCell(cell);
string etause = "错误";
if (item.AnalyStatus == eAnalyStatus.Normal)
etause = "正常";
if (item.AnalyStatus == eAnalyStatus.Missing)
etause = "数据缺失";
if (item.AnalyStatus == eAnalyStatus.Abnormal)
etause = "数据异常";
if (item.AnalyStatus == eAnalyStatus.Unkonw)
etause = "未知";
cell = CreateCell2("分析间隔", _fontSize11, 1, 1, 40, 0, Element.ALIGN_CENTER);
table.AddCell(cell);
cell = CreateCell2(item.Duration.ToString(), _fontSize11, 1, 1, 40, 0, Element.ALIGN_CENTER);
table.AddCell(cell);
cell = CreateCell2("分析状态", _fontSize11, 1, 1, 40, 0, Element.ALIGN_CENTER);
table.AddCell(cell);
cell = CreateCell2(etause, _fontSize11, 1, 1, 40, 0, Element.ALIGN_CENTER);
cell.BackgroundColor = BaseColor.Red;
if (item.AnalyStatus == eAnalyStatus.Normal)
cell.BackgroundColor = BaseColor.Green;
if (item.AnalyStatus == eAnalyStatus.Missing)
cell.BackgroundColor = BaseColor.Yellow;
if (item.AnalyStatus == eAnalyStatus.Abnormal)
cell.BackgroundColor = BaseColor.Orange;
if (item.AnalyStatus == eAnalyStatus.Unkonw)
cell.BackgroundColor = BaseColor.Gray;
table.AddCell(cell);
cell = CreateCell2("分析结果", _fontSize11, 1, 1, 150, 0, Element.ALIGN_CENTER);
table.AddCell(cell);
cell = CreateCell2(item.AnalyInfo, _fontSize11, 3, 1, 150, 0, Element.ALIGN_CENTER);
table.AddCell(cell);
table.SetWidths(widths);
_document.Add(table);
}
// cell.Rowspan = 4;
// table.SetWidths(widths);
// _document.Add(table);
//}
////添加水印
//public void AddWatermark()
//{
// if (_isPrintCorpWaterMark)
// {
// var waterMarkLogoFile = System.IO.Path.Combine(SPump.GlobeParas.DataFolder, "SelectReportWaterMark.png");
// if (System.IO.File.Exists(waterMarkLogoFile))
// {
// PdfContentByte cb = _writer.DirectContent;
// iTextSharp.text.Rectangle psize = _document.PageSize;
// float width = psize.Width;
// float height = psize.Height;
// iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(waterMarkLogoFile);
// image.ScalePercent(50);
// //水印的位置
// //var i = image.Width;
// image.SetAbsolutePosition(width / 2 - image.Width / 4, height / 2 - image.Height / 4);
// cb.AddImage(image);
// }
// }
// if (!string.IsNullOrEmpty(RefWaterMarkText))
// {
// Font font = new Font(Font.FontFamily.UNDEFINED, 30, Font.BOLD, new iTextSharp.text.BaseColor(100, 400, 400, 50));
// Phrase p = new Phrase(RefWaterMarkText, font);
// ColumnText.ShowTextAligned(_writer.DirectContent, Element.ALIGN_CENTER, p, _document.PageSize.Width - 100, _document.PageSize.Height - 100, 0);
// }
//}
//为英文时首字母大写
private PdfPCell CreateCell1(string name,
Font font = null, int col = 1, int row = 1, float rowHeight = 15, int disableNum = 0, int r = Element.ALIGN_LEFT)
{
Paragraph table_t = null;
PdfPCell cell = new PdfPCell();
if (font == null)
font = _fontSize8;
if (name == null)
{
name = "";
}
table_t = new Paragraph(name, font);
table_t.Leading = 9;
cell.Colspan = col;
cell.Rowspan = row;
cell.MinimumHeight = rowHeight;
cell.FixedHeight = rowHeight;
cell.DisableBorderSide(disableNum);
cell.Padding = 0;
cell.PaddingLeft = 3;
cell.UseAscender = true;
cell.UseDescender = true;
cell.HorizontalAlignment = Element.ALIGN_CENTER;//水平居中
cell.VerticalAlignment = Element.ALIGN_MIDDLE;//垂直居中
table_t.Alignment = r;
cell.AddElement(table_t);
return cell;
}
//绘制文本(可能有特殊字符)
private PdfPCell CreateCell2(string name,
Font font = null,
int col = 1, int row = 1, float rowHeight = 15, int disableNum = 0,
int r = Element.ALIGN_LEFT, int Paragraph = Element.ALIGN_LEFT, bool b = false, int strLength = 26)
{
Paragraph table_t = null;
PdfPCell cell = new PdfPCell();
if (font == null)
font = _fontSize8;
if (name == null)
{
name = "";
}
if (name.Length > 27 && b && name.Length > strLength)
{
name = name.Substring(0, strLength);
}
table_t = new Paragraph(name, font);
table_t.Alignment = Element.ALIGN_LEFT;
table_t.Leading = 9;
cell.Colspan = col;
cell.Rowspan = row;
cell.MinimumHeight = rowHeight;
cell.FixedHeight = rowHeight;
cell.DisableBorderSide(disableNum);
cell.Padding = 0;
cell.PaddingLeft = 3;
cell.UseAscender = true;
cell.UseDescender = true;
cell.HorizontalAlignment = Element.ALIGN_CENTER;//水平居中
cell.VerticalAlignment = Element.ALIGN_MIDDLE;//垂直居中
table_t.Alignment = r;
cell.AddElement(table_t);
return cell;
}
private PdfPCell CreateCell(double value,
Font font = null, int col = 1, int row = 1, float rowHeight = 15, int disableNum = 0, int r = Element.ALIGN_LEFT)
{
string value_v = string.Empty;
Paragraph table_t = null;
PdfPCell cell = new PdfPCell();
if (font == null)
font = _fontSize8;
if (value >= 0)
{
value_v = Math.Round(value, 4).ToString();
}
table_t = new Paragraph(value_v, font);
table_t.Leading = 9;
cell.Colspan = col;
cell.Rowspan = row;
cell.MinimumHeight = rowHeight;
cell.FixedHeight = rowHeight;
cell.DisableBorderSide(disableNum);
cell.Padding = 0;
cell.PaddingLeft = 3;
cell.UseAscender = true;
cell.UseDescender = true;
cell.HorizontalAlignment = Element.ALIGN_CENTER;//水平居中
cell.VerticalAlignment = Element.ALIGN_MIDDLE;//垂直居中
table_t.Alignment = r;
cell.AddElement(table_t);
return cell;
}
//约分
private PdfPCell CreateCellReduce(double value,
Font font = null, int col = 1, int row = 1, float rowHeight = 15, int disableNum = 0, int r = Element.ALIGN_LEFT)
{
string value_v = string.Empty;
Paragraph table_t = null;
PdfPCell cell = new PdfPCell();
if (font == null)
font = _fontSize8;
if (value >= 0)
{
value_v = Math.Round(value, 2).ToString();
}
table_t = new Paragraph(value_v, font);
table_t.Leading = 9;
cell.Colspan = col;
cell.Rowspan = row;
cell.MinimumHeight = rowHeight;
cell.FixedHeight = rowHeight;
cell.DisableBorderSide(disableNum);
cell.Padding = 0;
cell.PaddingLeft = 3;
cell.UseAscender = true;
cell.UseDescender = true;
cell.HorizontalAlignment = Element.ALIGN_CENTER;//水平居中
cell.VerticalAlignment = Element.ALIGN_MIDDLE;//垂直居中
table_t.Alignment = r;
cell.AddElement(table_t);
return cell;
}
//画单元格方法
private PdfPTable CreateTable(int spanNum, float percentage = 100)//建立表格
{
PdfPTable table1 = new PdfPTable(spanNum);//将表格分为10列
table1.WidthPercentage = percentage;//表格所占界面的百分比
return table1;
}
}
}
#endregion