表格插入多行文字
private void SetCellTextMuilt<T>(XWPFTable table, int iRow, int iCol, T[] setText, int ifontsize = 10,
ParagraphAlignment pcellAli = ParagraphAlignment.LEFT)
{
try
{
XWPFTableCell cell = table.GetRow(iRow).GetCell(iCol);
cell.SetVerticalAlignment(XWPFTableCell.XWPFVertAlign.TOP);
cell.RemoveParagraph(0); //删除原文字
//Set style of the table
foreach (T txt in setText)
{
XWPFParagraph para = cell.AddParagraph(); //创建新段落
para.Alignment = pcellAli; //对齐方式
XWPFRun run = para.CreateRun();
run.FontFamily = strFont; //字体
run.FontSize = ifontsize; //字号
run.IsBold = bIsBold; //加粗
run.IsItalic = false ; //斜体
run.AppendText(txt.ToString()); //文字
//run.SetColor("FF0000");//颜色
}
}
catch (Exception)
{
Console.WriteLine("Error");
}
}
转载:https://blog.csdn.net/mswsf/article/details/104540264