1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| /* This sample starts up a copy of Excel,
* makes it visible,
* puts the value "33" in cell A1,
* and leaves Excel running for the user.
*/
import excel.*;
import java.io.*;
import ezjcom.*;
public class ExcelSample1 {
public static void main(String args[])
{
try {
// Instantiate an Excel App
Global global = new Global();
// Retrieve the "_Application" interface, and set it visible
_Application app = (_Application) global.get_Global().getApplication().get_Application();
app.setVisible( true );
// Add an initial workbook
app.getWorkbooks().Add();
// Retrieve the active worksheet
_Worksheet wks = (_Worksheet) app.getActiveSheet();
// Retrieve a Range that refers to the cell A1
Range range = wks.getRange( new JComVariant( "A1" ));
// Set the value of the cell to "33"
range.setValue( new JComVariant( 33 ));
// Print the value of the cell
System.out.println( range.getValue());
// Do not Quit the application, leave it running
// for the user.
} catch (JComException ex) {
ex.printStackTrace();
} finally {
// Shut down COM connections and release all resources.
ezjcom.JComObject.JComShutdown();
}
}
} |
Partager