Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.jacob.com.*;
- import com.jacob.activeX.*;
- public class Lesson001
- {
- public static void main(String[] args) {
- ActiveXComponent excelApp = new ActiveXComponent("Excel.Application");
- try {
- excelApp.setProperty("Visible", new Variant(true));
- excelApp.setProperty("DisplayAlerts", new Variant(false)); //警告メッセージをOFF
- Dispatch workbooks = Dispatch.get(excelApp, "Workbooks").toDispatch();
- Dispatch workbook = Dispatch.call(workbooks, "Open", args[0], new Variant(false), new Variant(true)).toDispatch(); //ブックを読み取り専用で開く
- Dispatch worksheets = Dispatch.get(workbook, "Worksheets").toDispatch();
- for (int i=1;i<=Dispatch.get(worksheets, "Count").getInt();i++)
- {
- Dispatch sheet = Dispatch.call(worksheets, "Item", i).toDispatch();
- Variant v = Dispatch.call(sheet, "Name");
- if (!v.isNull())
- System.out.println(v.toString());
- }
- Dispatch.call(workbook, "Close");
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- excelApp.invoke("Quit", new Variant[] {});
- ComThread.Release();
- }
- }
- }
Add Comment
Please, Sign In to add comment