通过c++对c#语言进行封装操作word
下面链接的内容为如下代码,是通过c#对NPOI的使用来操作excel,我现在想通过c++对下列代码进行封装,从而达到在c++平台上进行使用的目的,但是未成功,不知道哪位大神有过类似经历,求指教~~~~积分不多,多多见谅。江湖救急~~~~~
https://www.cnblogs.com/sstn/p/9435337.html
const int NUM_OF_ROWS = 3;
const int NUM_OF_COLUMNS = 10;
static void CreateChart(IDrawing drawing, ISheet sheet, IClientAnchor anchor, string serie1, string serie2)
{
var chart = drawing.CreateChart(anchor) as XSSFChart;
//生成图例
var legend = chart.GetOrCreateLegend();
//图例位置
legend.Position = LegendPosition.TopRight;
//图表
var data = chart.ChartDataFactory.CreateLineChartData<double, double>(); //折线图
//var data = chart.ChartDataFactory.CreateScatterChartData<double, double>(); //散点图
// X轴.
var bottomAxis = chart.ChartAxisFactory.CreateCategoryAxis(AxisPosition.Bottom);
bottomAxis.IsVisible = false; //默认为true 不显示 设置为fase 显示坐标轴(BUG?)
//Y轴
IValueAxis leftAxis = chart.ChartAxisFactory.CreateValueAxis(AxisPosition.Left);
leftAxis.Crosses = (AxisCrosses.AutoZero);
leftAxis.IsVisible = false; //设置显示坐标轴
//数据源
IChartDataSource<double> xs = DataSources.FromNumericCellRange(sheet, new CellRangeAddress(0, 0, 0, NUM_OF_COLUMNS - 1));
IChartDataSource<double> ys1 = DataSources.FromNumericCellRange(sheet, new CellRangeAddress(1, 1, 0, NUM_OF_COLUMNS - 1));
IChartDataSource<double> ys2 = DataSources.FromNumericCellRange(sheet, new CellRangeAddress(2, 2, 0, NUM_OF_COLUMNS - 1));
//数据系列
var s1 = data.AddSeries(xs, ys1);
s1.SetTitle(serie1);
var s2 = data.AddSeries(xs, ys2);
s2.SetTitle(serie2);
chart.Plot(data, bottomAxis, leftAxis);
}
static void Main(string[] args)
{
IWorkbook wb = new XSSFWorkbook();
ISheet sheet = wb.CreateSheet("linechart");
// Create a row and put some cells in it. Rows are 0 based.
IRow row;
ICell cell;
for (int rowIndex = 0; rowIndex < NUM_OF_ROWS; rowIndex++)
{
row = sheet.CreateRow((short)rowIndex);
for (int colIndex = 0; colIndex < NUM_OF_COLUMNS; colIndex++)
{
cell = row.CreateCell((short)colIndex);
cell.SetCellValue(colIndex * (rowIndex + 1));
}
}
IDrawing drawing = sheet.CreateDrawingPatriarch();
//锚点
IClientAnchor anchor1 = drawing.CreateAnchor(0, 0, 0, 0, 0, 5, 10, 15);
CreateChart(drawing, sheet, anchor1, "title1","title2");
IClientAnchor anchor2 = drawing.CreateAnchor(0, 0, 0, 0, 0, 20, 10, 35);
CreateChart(drawing, sheet, anchor2, "s1", "s2");
using (FileStream fs =File.Create("test.xlsx"))
{
wb.Write(fs);
}
}
https://www.cnblogs.com/sstn/p/9435337.html
const int NUM_OF_ROWS = 3;
const int NUM_OF_COLUMNS = 10;
static void CreateChart(IDrawing drawing, ISheet sheet, IClientAnchor anchor, string serie1, string serie2)
{
var chart = drawing.CreateChart(anchor) as XSSFChart;
//生成图例
var legend = chart.GetOrCreateLegend();
//图例位置
legend.Position = LegendPosition.TopRight;
//图表
var data = chart.ChartDataFactory.CreateLineChartData<double, double>(); //折线图
//var data = chart.ChartDataFactory.CreateScatterChartData<double, double>(); //散点图
// X轴.
var bottomAxis = chart.ChartAxisFactory.CreateCategoryAxis(AxisPosition.Bottom);
bottomAxis.IsVisible = false; //默认为true 不显示 设置为fase 显示坐标轴(BUG?)
//Y轴
IValueAxis leftAxis = chart.ChartAxisFactory.CreateValueAxis(AxisPosition.Left);
leftAxis.Crosses = (AxisCrosses.AutoZero);
leftAxis.IsVisible = false; //设置显示坐标轴
//数据源
IChartDataSource<double> xs = DataSources.FromNumericCellRange(sheet, new CellRangeAddress(0, 0, 0, NUM_OF_COLUMNS - 1));
IChartDataSource<double> ys1 = DataSources.FromNumericCellRange(sheet, new CellRangeAddress(1, 1, 0, NUM_OF_COLUMNS - 1));
IChartDataSource<double> ys2 = DataSources.FromNumericCellRange(sheet, new CellRangeAddress(2, 2, 0, NUM_OF_COLUMNS - 1));
//数据系列
var s1 = data.AddSeries(xs, ys1);
s1.SetTitle(serie1);
var s2 = data.AddSeries(xs, ys2);
s2.SetTitle(serie2);
chart.Plot(data, bottomAxis, leftAxis);
}
static void Main(string[] args)
{
IWorkbook wb = new XSSFWorkbook();
ISheet sheet = wb.CreateSheet("linechart");
// Create a row and put some cells in it. Rows are 0 based.
IRow row;
ICell cell;
for (int rowIndex = 0; rowIndex < NUM_OF_ROWS; rowIndex++)
{
row = sheet.CreateRow((short)rowIndex);
for (int colIndex = 0; colIndex < NUM_OF_COLUMNS; colIndex++)
{
cell = row.CreateCell((short)colIndex);
cell.SetCellValue(colIndex * (rowIndex + 1));
}
}
IDrawing drawing = sheet.CreateDrawingPatriarch();
//锚点
IClientAnchor anchor1 = drawing.CreateAnchor(0, 0, 0, 0, 0, 5, 10, 15);
CreateChart(drawing, sheet, anchor1, "title1","title2");
IClientAnchor anchor2 = drawing.CreateAnchor(0, 0, 0, 0, 0, 20, 10, 35);
CreateChart(drawing, sheet, anchor2, "s1", "s2");
using (FileStream fs =File.Create("test.xlsx"))
{
wb.Write(fs);
}
}
...全文
相关推荐
Csharplanguage.rar_C#编程_WORD_
本文描述 C# 编程语言的语法、语义和设计
批量处理Word文档页眉页脚的C#源代码
Microsoft.Office.Interop.Word 命名空间提供了一组丰富的 API,允许开发人员使用 .NET 语言(如 C#)来编程控制 Word 文档。这个命名空间位于 Office Primary Interop Assemblies (PIA) 中,它封装了 Word 对象模型,从而可以操作文档的几乎每一个方面,包括但不限于创建新文档、读取或写入文本、插入图表、图片和其他媒体,以及添加和编辑页眉页脚。
各类语言编程规范细则word文档
详细描述编程语言规范细则,包括C++, Java, JS, C#, SQL等等,有助与代码管理,形成良好编码习惯,可用于教育,工作中规范
基于C#的操作Excel源码.zip
c# 基于 DocumentFormat.OpenXml 操作 Excel 核心代码添加注释非常齐全,简单操作创建和修改,没有再进一步封装,可以自己封装
DOT文件转换为DOC文件-易语言
DOT文件转换为DOC文件


