将 Excel VBA 转换为 C++Builder OLE API
Convert Excel VBA to C++Builder OLE API
如何将以下 VBA 代码转换为 OLE 中的 c++ 生成器?谢谢。
Range("A10:B28").Select
ActiveSheet.Shapes.AddChart2(240, xlXYScatter).Select
ActiveChart.SetSourceData Source:=Range("Sheet1!$A:$B")
ActiveSheet.Shapes("test1").IncrementLeft -288.5293700787
ActiveSheet.Shapes("test1").IncrementTop -39.7059055118
我已经尝试了下面的代码,C++ 构建器在最后一行崩溃了
#include <excel_2k.h>
outXL = Variant::CreateObject("excel.application");
outXL.OlePropertySet("Visible", true);
outWorkbooks = outXL.OlePropertyGet("Workbooks");
outWorkbook = outWorkbooks.OleFunction("Open", "D:\test.xls");
outWorkSheets = outWorkbook.OlePropertyGet("Worksheets");
outActiveSheet = outWorkbook.OlePropertyGet("Worksheets", 0);
outActiveSheet.OlePropertyGet("Activate");
Range=outActiveSheet.OlePropertyGet("Range",
outActiveSheet.OlePropertyGet("Cells",5,1),
outActiveSheet.OlePropertyGet("Cells",20,2));
Chart = outActiveSheet.OlePropertyGet("Shapes").OleFunction("AddChart2");
//=========This line Dump ERROR=========
Chart.OlePropertySet("ChartType",xlXYScatter);
IDK,如果这是答案,但是ISTM你需要修改这里的代码
Chart = outActiveSheet.OlePropertyGet("Shapes").OleFunction("AddChart2", 240, xlXYScatter);
这就是 VBA 中的调用方式。你只有 OleFunction("AddChart2")
函数调用后Chart的值是多少?
我已经修复了这个问题,请参考下面的代码...
Chart = outXL.OlePropertyGet("Charts").OleFunction("Add");
Chart.OlePropertySet("ChartType", xlXYScatter);
Range=outActiveSheet.OlePropertyGet("Range",
outActiveSheet.OlePropertyGet("Cells",iDrawRowFrom,iDrawColFrom),
outActiveSheet.OlePropertyGet("Cells",iDrawRowTo,iDrawColTo));
Chart.OleProcedure("SetSourceData", Range);
Chart.OleFunction("Location", 2, strOutSheetName.c_str());
如何将以下 VBA 代码转换为 OLE 中的 c++ 生成器?谢谢。
Range("A10:B28").Select
ActiveSheet.Shapes.AddChart2(240, xlXYScatter).Select
ActiveChart.SetSourceData Source:=Range("Sheet1!$A:$B")
ActiveSheet.Shapes("test1").IncrementLeft -288.5293700787
ActiveSheet.Shapes("test1").IncrementTop -39.7059055118
我已经尝试了下面的代码,C++ 构建器在最后一行崩溃了
#include <excel_2k.h>
outXL = Variant::CreateObject("excel.application");
outXL.OlePropertySet("Visible", true);
outWorkbooks = outXL.OlePropertyGet("Workbooks");
outWorkbook = outWorkbooks.OleFunction("Open", "D:\test.xls");
outWorkSheets = outWorkbook.OlePropertyGet("Worksheets");
outActiveSheet = outWorkbook.OlePropertyGet("Worksheets", 0);
outActiveSheet.OlePropertyGet("Activate");
Range=outActiveSheet.OlePropertyGet("Range",
outActiveSheet.OlePropertyGet("Cells",5,1),
outActiveSheet.OlePropertyGet("Cells",20,2));
Chart = outActiveSheet.OlePropertyGet("Shapes").OleFunction("AddChart2");
//=========This line Dump ERROR=========
Chart.OlePropertySet("ChartType",xlXYScatter);
IDK,如果这是答案,但是ISTM你需要修改这里的代码
Chart = outActiveSheet.OlePropertyGet("Shapes").OleFunction("AddChart2", 240, xlXYScatter);
这就是 VBA 中的调用方式。你只有 OleFunction("AddChart2")
函数调用后Chart的值是多少?
我已经修复了这个问题,请参考下面的代码...
Chart = outXL.OlePropertyGet("Charts").OleFunction("Add");
Chart.OlePropertySet("ChartType", xlXYScatter);
Range=outActiveSheet.OlePropertyGet("Range",
outActiveSheet.OlePropertyGet("Cells",iDrawRowFrom,iDrawColFrom),
outActiveSheet.OlePropertyGet("Cells",iDrawRowTo,iDrawColTo));
Chart.OleProcedure("SetSourceData", Range);
Chart.OleFunction("Location", 2, strOutSheetName.c_str());