作者:敏--MM | 来源:互联网 | 2023-06-10 17:06
所用Excel(.xsl)只有一个表单(sheet)名为“红米note2充电”,该表单中无表头(即第一行就是数据),分为两列(即只有A、B列)。如下图示:现已可成功连接Excel,但具体使用
所用Excel(.xsl)只有一个表单(sheet)名为“红米note2充电”,该表单中无表头(即第一行就是数据),分为两列(即只有A、B列)。如下图示:
msoFalse, msoTrue, l, t, w, h);
}
catch(_com_error &e)
{
dump_com_error(e);
}
//插入饼状图
try
{
pSheet->Range["A2"]->Value2 = "Company A";
pSheet->Range["B2"]->Value2 = "Company B";
pSheet->Range["C2"]->Value2 = "Company C";
pSheet->Range["D2"]->Value2 = "Company D";
pSheet->Range["A3"]->Value2 = 75.0;
pSheet->Range["B3"]->Value2 = 14.0;
pSheet->Range["C3"]->Value2 = 7.0;
pSheet->Range["D3"]->Value2 = 4.0;
pSheet->Range["A4"]->Value2 = 75.0;
pSheet->Range["B4"]->Value2 = 14.0;
pSheet->Range["C4"]->Value2 = 7.0;
pSheet->Range["D4"]->Value2 = 4.0;
RangePtr pRange = pSheet->Range["A2:D3"];
_ChartPtr pChart = pBook->Charts->Add();
pChart->ChartWizard((Range*) pRange, (long) Office::xl3DPie, 7L, (long) Office::xlRows,
1L, 0L, 2L, "Market Share");
}
catch( _com_error &e)
{
dump_com_error(e);
}
//设置页面格式
try
{
PageSetupPtr pPageSet = pSheet->PageSetup;
pPageSet->PutPaperSize( xlPaperA4 ); //A4
pPageSet->CenterHorizontally = VARIANT_TRUE; //水平居中
pPageSet->PutOrientation( xlLandscape ); //横向打印
pPageSet->PrintArea = "$A$1:$J$22"; //打印区域
}
catch(_com_error &e)
{
dump_com_error(e);
}
Sleep(6000);
pBook->PutSaved(0, VARIANT_TRUE);
pXL->Quit();
}
catch(_com_error &e)
{
dump_com_error(e);
}
return 0;
}