下载jacob-1.19.zip
https://sourceforge.net/projects/jacob-project/
jacob-1.19-x64.dll放到C:\Windows\System32目录下
jacob.jar引入项目
Sub test1()
Worksheets("Sheet1").Range("A5").Value = 22
MsgBox "工作表Sheet1内单元格A5中的值为" _
& Worksheets("Sheet1").Range("A5").Value
End Sub
excel需要保存为启用宏的工作簿,后缀为.xlsm
文档特定设置 宏
JacobExcelTool.java
/*
* Copyright © 2019 [email protected] Inc. All rights reserved
* @package: com.ibm.jacob
* @version V1.0
*/
package com.ibm.jacob;
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.ComThread;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;
/**
* @author Moses *
* @Date 2019/4/1
*/
public class JacobExcelTool {
/**
* Excel对象
*/
private ActiveXComponent xl = null;
/**
* 工作簿对象
*/
private Dispatch workbooks = null;
/**
* 具体工作簿
*/
private Dispatch workbook = null;
/**
* 获得sheets集合对象
*/
private Dispatch sheets = null;
/**
* 当前sheet
*/
private Dispatch currentSheet = null;
public ActiveXComponent getXl() {
return xl;
}
public Dis