|
set objExcel = createObject(“excel.application”)
objExcel.visible = true
set objWorkbook = objExcel.workbooks.add()
ser objSheet = objWorkbook.worksheets(1)
objSheet.cells(1,1) = "行业"
objSheet.cells(2,1) = "电器"
objSheet.cells(3,1) = "数码"
objSheet.cells(1,2) = 数量
objSheet.cells(2,2) = 89
objSheet.cells(3,2) = 100
set objRange = objSheet.UsedRange
objRange.Select
set myCharts = objExcel.Charts
myCharts.add()
set objChart = myCharts(1)
objChart.Activate
objChart.hasLegend = true
objChart.ChartType = 5 'xlpie
'.....
objWorkbook.saveAs("F:\01\pie1.docx")
这段代码命名为xx.vbs
可以在Java中调用执行的
public class VbsTest {
public static void main(String[] args) {
buildWord();
}
public static void buildWord(){
String[] cmd = new String[]{"wscript","F:/01/vbs/copyChart.vbs","param"};
try {
Process process = Runtime.getRuntime().exec(cmd);
//val是返回值,返回0表示正常执行
int val = process.waitFor();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
|
|