程序员开发实例大全宝库

网站首页 > 编程文章 正文

【新功能!】Spire.Doc 11.5.6 支持了添加图表的功能

zazugpt 2024-08-09 12:19:17 编程文章 137 ℃ 0 评论

Spire.Doc 11.5.6已发布。本次更新支持了添加图表的功能和支持了添加SVG文档的功能。此外,该版本也支持打印多页到一页的功能,以及支持了操作页面的功能,比如获取页面的内容以及内容的坐标。详情请阅读以下内容。

新功能:

  • 支持了添加图表的功能。
//创建word文档
Document document = new Document();

//新建一个节
Section section = document.AddSection();

//创建新段落并附加文本
section.AddParagraph().AppendText("Column chart.");

//创建一个新节以附加柱形图
Paragraph newPara = section.AddParagraph();
ShapeObject shape = newPara.AppendChart(ChartType.Column, 500, 300);

//清除图表的系列数据,以一个干净的图表开始。
Chart chart = shape.Chart;
chart.Series.Clear();

//将自定义系列添加到图表中,其中X轴为类别,Y轴为相应的大数值。
chart.Series.Add("Test Series",
    new[] { "Word", "PDF", "Excel", "GoogleDocs", "Office" },
    new double[] { 1900000, 850000, 2100000, 600000, 1500000 });

//将Y轴刻度标签的数字格式设置为使用逗号对数字进行分组。 
chart.AxisY.NumberFormat.FormatCode = "#,##0";

//保存结果文档
document.SaveToFile("AppendColumnChart.docx", FileFormat.Docx);
//创建word文档
Document document = new Document();

//新建一个节
Section section = document.AddSection();

//创建新段落并附加文本
section.AddParagraph().AppendText("Bubble chart.");

//创建一个新段落并打开气泡图
Paragraph newPara = section.AddParagraph();
ShapeObject shape = newPara.AppendChart(ChartType.Bubble, 500, 300);

//清除字符的序列数据,以一个干净的图表开始
Chart chart = shape.Chart;
chart.Series.Clear();

// 添加带有X/Y坐标和每个气泡直径的自定义系列
ChartSeries series = chart.Series.Add("Test Series",
    new[] { 2.9, 3.5, 1.1, 4.0, 4.0 },
    new[] { 1.9, 8.5, 2.1, 6.0, 1.5 },
    new[] { 9.0, 4.5, 2.5, 8.0, 5.0 });

//保存doc文件
document.SaveToFile("AppendBubbleChart.docx", FileFormat.Docx);
//创建word文档
Document document = new Document();

//新建一个节
Section section = document.AddSection();

//创建新段落并附加文本
section.AddParagraph().AppendText("Line chart.");

//创建一个新段落以附加折线图
Paragraph newPara = section.AddParagraph();
ShapeObject shape = newPara.AppendChart(ChartType.Line, 500, 300);

//清除折线图的系列数据以从干净的图表开始
Chart chart = shape.Chart;
ChartTitle title = chart.Title;
title.Text = "My Chart";
ChartSeriesCollection seriesColl = chart.Series;
seriesColl.Clear();

//在图表内设置新数据
string[] categories = { "C1", "C2", "C3", "C4", "C5", "C6" };
seriesColl.Add("AW Series 1", categories, new double[] { 1, 2, 2.5, 4, 5, 6 });
seriesColl.Add("AW Series 2", categories, new double[] { 2, 3, 3.5, 6, 6.5, 7 });

//保存doc文件
document.SaveToFile("AppendLineChart.docx", FileFormat.Docx);
//创建word文档
Document document = new Document();

//新建一个节
Section section = document.AddSection();

//创建新段落并附加文本
section.AddParagraph().AppendText("Pie chart.");

//创建一个新段落以附加饼图
Paragraph newPara = section.AddParagraph();
ShapeObject shape = newPara.AppendChart(ChartType.Pie, 500, 300);
Chart chart = shape.Chart;

//插入一个自定义图表系列,其中包含每个扇区的类别名称及其频率值。
ChartSeries series = chart.Series.Add("Test Series",
  new[] { "Word", "PDF", "Excel" },
  new[] { 2.7, 3.2, 0.8 });

//保存到docx文件。
document.SaveToFile("AppendPieChart.docx", FileFormat.Docx);
//创建word文档
Document document = new Document();

//新建一个节
Section section = document.AddSection();

//创建新段落并附加文本
section.AddParagraph().AppendText("Scatter chart.");

//创建一个新段落以附加散点图
Paragraph newPara = section.AddParagraph();
ShapeObject shape = newPara.AppendChart(ChartType.Scatter, 450, 300);
Chart chart = shape.Chart;

//清除图表的系列数据,以一个干净的图表开始
chart.Series.Clear();

//插入五个点的X/Y坐标系列
chart.Series.Add("Scatter chart",
    new[] { 1.0, 2.0, 3.0, 4.0, 5.0 },
    new[] { 1.0, 20.0, 40.0, 80.0, 160.0 });

//保存到docx文件
document.SaveToFile("AppendScatterChart.docx", FileFormat.Docx);
//创建word文档
Document document = new Document();

//新建一个节
Section section = document.AddSection();

//创建新段落并附加文本
section.AddParagraph().AppendText("Surface3D chart.");

//创建新段落以附加曲面三维图表
Paragraph newPara = section.AddParagraph();
ShapeObject shape = newPara.AppendChart(ChartType.Surface3D, 500, 300);

//清除其系列数据,以一个干净的图表开始
Chart chart = shape.Chart;
chart.Series.Clear();


chart.Title.Text = "My chart";

//添加三个系列
chart.Series.Add("Series 1",
    new string[] { "Word", "PDF", "Excel", "GoogleDocs", "Office" },
    new double[] { 1900000, 850000, 2100000, 600000, 1500000 });

chart.Series.Add("Series 2",
    new string[] { "Word", "PDF", "Excel", "GoogleDocs", "Office" },
    new double[] { 900000, 50000, 1100000, 400000, 2500000 });

chart.Series.Add("Series 3",
    new string[] { "Word", "PDF", "Excel", "GoogleDocs", "Office" },
    new double[] { 500000, 820000, 1500000, 400000, 100000 });

//保存到docx文件.
document.SaveToFile("AppendSurface3DChart.docx", FileFormat.Docx);
//创建word文档
Document document = new Document();

//新建一个节
Section section = document.AddSection();

//创建新段落并附加文本
section.AddParagraph().AppendText("Bar chart.");

//创建一个新段落以附加条形图
Paragraph newPara = section.AddParagraph();
ShapeObject chartShape = newPara.AppendChart(ChartType.Bar, 400, 300);
Chart chart = chartShape.Chart;

//使用“标题”属性为条形图提供一个标题,该标题显示在图表区域的顶部中心。
ChartTitle title = chart.Title;
title.Text = "My Chart";

//将“Show”属性设置为“true”以使标题可见。 
title.Show = true;

//将“Overlay”属性设置为“true”。允许其他图表元素与标题重叠,从而给它们更多的空间
title.Overlay = true;

//保存到docx文件
document.SaveToFile("AppendBarChart.docx", FileFormat.Docx);
  • 支持了添加SVG文档的功能。
Document document = new Document();
Section section = document.AddSection();
string svgFile = "sample.svg";
Paragraph para = section.AddParagraph();
DocPicture svgPicture = para.AppendPicture(svgFile);
svgPicture.Width = 200;
svgPicture.Height = 200;
String DocxResult = "Result-AddSvg.docx";
document.SaveToFile(DocxResult, FileFormat.Docx2016);
  • 支持打印多页到一页的功能。
Document doc = new Document();
doc.LoadFromFile(inputFile, FileFormat.Docx);
System.Windows.Forms.PrintDialog printDialog = new System.Windows.Forms.PrintDialog();
printDialog.PrinterSettings.PrintToFile = true;
printDialog.PrinterSettings.PrintFileName = "sample-new-4.xps";
doc.PrintDialog = printDialog;
doc.PrintMultipageToOneSheet(PagesPreSheet.FourPages, true);
  • 支持了操作页面的功能比如获取页面的内容以及内容的坐标。
Document doc = new Document();
doc.LoadFromFile(inputFile, FileFormat.Docx);
FixedLayoutDocument layoutDoc = new FixedLayoutDocument(doc);

// 访问第一页的行并打印到控制台。
FixedLayoutLine line = layoutDoc.Pages[0].Columns[0].Lines[0];

StringBuilder stringBuilder = new StringBuilder();
stringBuilder.AppendLine("Line: " + line.Text);

//使用渲染的行,可以返回文档对象模型中的原始段落。
Paragraph para = line.Paragraph;
stringBuilder.AppendLine("Paragraph text: " + para.Text);

// 以纯文本格式(包括页眉和页脚)检索第一页上显示的所有文本。
string pageText = layoutDoc.Pages[0].Text;
stringBuilder.AppendLine(pageText);

// 循环遍历文档中的每一页,并打印每页上显示的行数。
foreach (FixedLayoutPage page in layoutDoc.Pages)
{
    LayoutCollection lines = page.GetChildEntities(LayoutElementType.Line, true);
    stringBuilder.AppendLine("Page " + page.PageIndex + " has " + lines.Count + " lines.");
}

// 此方法为任何给定节点提供布局实体的反向查找
// (页眉和页脚中的管路和节点除外)。
stringBuilder.AppendLine("The lines of the first paragraph:");
foreach (FixedLayoutLine paragraphLine in layoutDoc.GetLayoutEntitiesOfNode(
    ((Section)doc.FirstChild).Body.Paragraphs[0]))
{
    stringBuilder.AppendLine(paragraphLine.Text.Trim());
    stringBuilder.AppendLine(paragraphLine.Rectangle.ToString());
}
File.WriteAllText("page.txt", stringBuilder.ToString());

获取Spire.Doc 11.5.6请点击:

Spire.Doc for .NET | 下载

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表