forked from java-native-access/jna
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
116 changed files
with
17,367 additions
and
9,606 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
contrib/msoffice/src/com/sun/jna/platform/win32/COM/office/MSExcel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package com.sun.jna.platform.win32.COM.office; | ||
|
||
import com.sun.jna.platform.win32.Variant.VARIANT; | ||
import com.sun.jna.platform.win32.COM.COMException; | ||
import com.sun.jna.platform.win32.COM.COMLateBindingObject; | ||
import com.sun.jna.platform.win32.COM.IDispatch; | ||
|
||
public class MSExcel extends COMLateBindingObject { | ||
|
||
public MSExcel() throws COMException { | ||
super("Excel.Application", false); | ||
} | ||
|
||
public MSExcel(boolean visible) throws COMException { | ||
this(); | ||
this.setVisible(visible); | ||
} | ||
|
||
public void setVisible(boolean bVisible) throws COMException { | ||
this.setProperty("Visible", bVisible); | ||
} | ||
|
||
public String getVersion() throws COMException { | ||
return this.getStringProperty("Version"); | ||
} | ||
|
||
public void newExcelBook() throws COMException { | ||
this.invokeNoReply("Add", getWorkbooks()); | ||
} | ||
|
||
public void openExcelBook(String filename, boolean bVisible) | ||
throws COMException { | ||
// OpenDocument | ||
this.invokeNoReply("Open", getWorkbooks(), new VARIANT(filename)); | ||
} | ||
|
||
public void closeActiveWorkbook(boolean bSave) throws COMException { | ||
this.invokeNoReply("Close", getActiveWorkbook(), new VARIANT(bSave)); | ||
} | ||
|
||
public void quit() throws COMException { | ||
this.invokeNoReply("Quit"); | ||
} | ||
|
||
public void insertValue(String range, String value) throws COMException { | ||
Range pRange = new Range(this.getAutomationProperty("Range", | ||
this.getActiveSheet(), new VARIANT(range))); | ||
this.setProperty("Value", pRange, new VARIANT(value)); | ||
} | ||
|
||
public Application getApplication() { | ||
return new Application(this.getAutomationProperty("Application")); | ||
} | ||
|
||
public ActiveWorkbook getActiveWorkbook() { | ||
return new ActiveWorkbook(this.getAutomationProperty("ActiveWorkbook")); | ||
} | ||
|
||
public Workbooks getWorkbooks() { | ||
return new Workbooks(this.getAutomationProperty("WorkBooks")); | ||
} | ||
|
||
public ActiveSheet getActiveSheet() { | ||
return new ActiveSheet(this.getAutomationProperty("ActiveSheet")); | ||
} | ||
|
||
public class Application extends COMLateBindingObject { | ||
|
||
public Application(IDispatch iDispatch) throws COMException { | ||
super(iDispatch); | ||
} | ||
} | ||
|
||
public class Workbooks extends COMLateBindingObject { | ||
public Workbooks(IDispatch iDispatch) throws COMException { | ||
super(iDispatch); | ||
} | ||
} | ||
|
||
public class ActiveWorkbook extends COMLateBindingObject { | ||
public ActiveWorkbook(IDispatch iDispatch) throws COMException { | ||
super(iDispatch); | ||
} | ||
} | ||
|
||
public class ActiveSheet extends COMLateBindingObject { | ||
public ActiveSheet(IDispatch iDispatch) throws COMException { | ||
super(iDispatch); | ||
} | ||
} | ||
|
||
public class Range extends COMLateBindingObject { | ||
public Range(IDispatch iDispatch) throws COMException { | ||
super(iDispatch); | ||
} | ||
} | ||
} |
101 changes: 101 additions & 0 deletions
101
contrib/msoffice/src/com/sun/jna/platform/win32/COM/office/MSOfficeDemo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package com.sun.jna.platform.win32.COM.office; | ||
|
||
import java.io.File; | ||
|
||
import com.sun.jna.platform.win32.COM.COMException; | ||
import com.sun.jna.platform.win32.WinDef.LONG; | ||
|
||
public class MSOfficeDemo { | ||
|
||
/** | ||
* @param args | ||
*/ | ||
public static void main(String[] args) { | ||
new MSOfficeDemo(); | ||
} | ||
|
||
private String currentWorkingDir = new File("").getAbsolutePath() | ||
+ File.separator; | ||
|
||
public MSOfficeDemo() { | ||
this.testMSWord(); | ||
// this.testMSExcel(); | ||
} | ||
|
||
public void testMSWord() { | ||
MSWord msWord = null; | ||
LONG wdFormatPDF = new LONG(17); // PDF format. | ||
LONG wdFormatRTF = new LONG(6); // Rich text format (RTF). | ||
LONG wdFormatHTML = new LONG(8); // Standard HTML format. | ||
|
||
try { | ||
msWord = new MSWord(); | ||
System.out.println("MSWord version: " + msWord.getVersion()); | ||
|
||
msWord.setVisible(true); | ||
// msWord.newDocument(); | ||
msWord.openDocument(currentWorkingDir + "jnatest.doc", true); | ||
msWord.insertText("Hello from JNA!"); | ||
// wait 10sec. before closing | ||
Thread.currentThread().sleep(10000); | ||
// save in different formats | ||
// pdf format is only supported in MSWord 2007 and above | ||
// msWord.SaveAs("C:\\TEMP\\jnatestSaveAs.pdf", wdFormatPDF); | ||
msWord.SaveAs("C:\\TEMP\\jnatestSaveAs.rtf", wdFormatRTF); | ||
msWord.SaveAs("C:\\TEMP\\jnatestSaveAs.html", wdFormatHTML); | ||
// close and save the document | ||
msWord.closeActiveDocument(true); | ||
msWord.setVisible(true); | ||
msWord.newDocument(); | ||
// msWord.openDocument(currentWorkingDir + "jnatest.doc", true); | ||
msWord.insertText("Hello from JNA!"); | ||
// close and save the document | ||
msWord.closeActiveDocument(true); | ||
// wait then close word | ||
msWord.quit(); | ||
} catch(InterruptedException ie) { | ||
ie.printStackTrace(); | ||
} catch (COMException e) { | ||
if (e.getExcepInfo() != null) { | ||
System.out | ||
.println("bstrSource: " + e.getExcepInfo().bstrSource); | ||
System.out.println("bstrDescription: " | ||
+ e.getExcepInfo().bstrDescription); | ||
} | ||
|
||
// print stack trace | ||
e.printStackTrace(); | ||
|
||
if (msWord != null) | ||
msWord.quit(); | ||
} | ||
} | ||
|
||
public void testMSExcel() { | ||
MSExcel msExcel = null; | ||
|
||
try { | ||
msExcel = new MSExcel(); | ||
System.out.println("MSExcel version: " + msExcel.getVersion()); | ||
msExcel.setVisible(true); | ||
// msExcel.newExcelBook(); | ||
msExcel.openExcelBook(currentWorkingDir + "jnatest.xls", true); | ||
msExcel.insertValue("A1", "Hello from JNA!"); | ||
// wait 10sec. before closing | ||
Thread.currentThread().sleep(10000); | ||
// close and save the active sheet | ||
msExcel.closeActiveWorkbook(true); | ||
msExcel.setVisible(true); | ||
// msExcel.newExcelBook(); | ||
msExcel.openExcelBook(currentWorkingDir + "jnatest.xls", true); | ||
msExcel.insertValue("A1", "Hello from JNA!"); | ||
// close and save the active sheet | ||
msExcel.closeActiveWorkbook(true); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
|
||
if (msExcel != null) | ||
msExcel.quit(); | ||
} | ||
} | ||
} |
Oops, something went wrong.