实现方法如7a64e78988e69d83330下:/// //" />
乔山办公网我们一直在努力
您的位置:乔山办公网 > excel表格制作 > C++把数据导出到Excel并自动生成折线图,怎么实现

C++把数据导出到Excel并自动生成折线图,怎么实现

作者:乔山办公网日期:

返回目录:excel表格制作


柱状图生成区域可以设置的大些

实现方法如7a64e78988e69d83330下:

/// <summary>
/// 读取Excel文档
/// </summary>

/// <param name="Path">文件名称</param>
/// <returns>返回一个数据集</returns>
public DataSet ExcelToDS(string Path)
{
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" +"Data Source="+ Path +";"+"Extended Properties=Excel 8.0;";
OleDbConnection conn = new OleDbConnection(strConn);
conn.Open();
string strExcel = "";
OleDbDataAdapter myCommand = null;
DataSet ds = null;
strExcel="select * from [sheet1$]";
myCommand = new OleDbDataAdapter(strExcel, strConn);
ds = new DataSet();
myCommand.Fill(ds,"table1");
return ds;
}
/// <summary>
/// 写入Excel文档
/// </summary>
/// <param name="Path">文件名称</param>
public bool SaveFP2toExcel(string Path)
{
try
{
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" +"Data Source="+ Path +";"+"Extended Properties=Excel 8.0;";
OleDbConnection conn = new OleDbConnection(strConn);
conn.Open();
System.Data.OleDb.OleDbCommand cmd=new OleDbCommand ();
cmd.Connection =conn;
//cmd.CommandText ="UPDATE [sheet1$] SET 姓名=’2016-01-01’ WHERE 工号=’日期’";
//cmd.ExecuteNonQuery ();
for(int i=0;i<fp2.Sheets [0].RowCount -1;i++)
{
if(fp2.Sheets [0].Cells[i,0].Text!="")
{
cmd.CommandText ="INSERT INTO [sheet1$] (工号,姓名,部门,职务,日期,时间) VALUES(’"+fp2.Sheets [0].Cells[i,0].Text+ "’,’"+
fp2.Sheets [0].Cells[i,1].Text+"’,’"+fp2.Sheets [0].Cells[i,2].Text+"’,’"+fp2.Sheets [0].Cells[i,3].Text+
"’,’"+fp2.Sheets [0].Cells[i,4].Text+"’,’"+fp2.Sheets [0].Cells[i,5].Text+"’)";
cmd.ExecuteNonQuery ();
}
}
conn.Close ();
return true;
}
catch(System.Data.OleDb.OleDbException ex)
{
System.Diagnostics.Debug.WriteLine ("写入Excel发生错误:"+ex.Message );
}
return false;
}
常用的有Apache POI组件,一个apache基金会开发的操作微软文档的API。
文档介绍请参考下面地址:http://poi.apache.org/

报表是现成的,录制宏就可以了

相关阅读

关键词不能为空
极力推荐
  • Microsoft Excel 2010 for <em>mac</em> 如...-excel

  • 第一步:选择[数据]-[来工具]-[验证]-[数据验证],进入下拉设置对话框MAC版office 2011 表格设置下拉选项步骤MAC版office 2011 表格设置下拉选项步骤第二步:对话框中,在[

ppt怎么做_excel表格制作_office365_word文档_365办公网