|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
Java编译的是字节码,跟C++相反,启动不够快,效率不够高,难以精确控制内存,但是优点是编程比C++容易,代码比较安全但是容易留下性能隐患,跨平台靠字节码在各个平台复制(一处编译到处调试)
packagecom.jrkui.example.excel;- importorg.eclipse.swt.SWT;importorg.eclipse.swt.layout.FillLayout;importorg.eclipse.swt.ole.win32.OLE;importorg.eclipse.swt.ole.win32.OleAutomation;importorg.eclipse.swt.ole.win32.OleClientSite;importorg.eclipse.swt.ole.win32.OleFrame;importorg.eclipse.swt.ole.win32.Variant;importorg.eclipse.swt.widgets.Display;importorg.eclipse.swt.widgets.Shell;publicclassColorRangeShell{publicstaticvoidmain(String[]args){newColorRangeShell().open();}publicvoidopen(){Displaydisplay=Display.getDefault();Shellshell=newShell();shell.setText("ColorRangeShell");shell.setSize(400,300);shell.setLayout(newFillLayout());createExcelPart(shell);shell.open();while(!shell.isDisposed())if(!display.readAndDispatch())display.sleep();display.dispose();}privatestaticfinalintSHEET_ID=0x000001e5;privatestaticfinalintCELL_ID=0x000000c5;privatevoidcreateExcelPart(Shellshell){OleFrameframe=newOleFrame(shell,SWT.NONE);OleClientSiteclientSite=newOleClientSite(frame,SWT.NONE,"Excel.Sheet");clientSite.doVerb(OLE.OLEIVERB_SHOW);OleAutomationworkbook=newOleAutomation(clientSite);OleAutomationworksheet=workbook.getProperty(SHEET_ID,newVariant[]{newVariant(1)}).getAutomation();//取得单位格OleAutomationcellA1=worksheet.getProperty(CELL_ID,newVariant[]{newVariant("A1")}).getAutomation();OleAutomationcellD1=worksheet.getProperty(CELL_ID,newVariant[]{newVariant("D1")}).getAutomation();//取得单位格地区OleAutomationareaA3D5=worksheet.getProperty(CELL_ID,newVariant[]{newVariant("A3"),newVariant("D5")}).getAutomation();colorRangeByRed(cellA1);colorRangeByRed(cellD1);colorRangeByRed(areaA3D5);}/***取得interior的办法在Range中的Id*/privatestaticfinalintINTERIOR=0x00000081;/***为ColorIndex赋值的办法在interior中的Id*/privatestaticfinalintCOLOR_INDEX=0x00000061;/***白色在Excel的Index为3*/privatestaticfinalintRED=3;/***用白色作为Range的背景致*@paramautomation*/privatevoidcolorRangeByRed(OleAutomationautomation){//取得interiorOleAutomationinterior=automation.getProperty(INTERIOR).getAutomation();//设置色彩interior.setProperty(COLOR_INDEX,newVariant(RED));}}
复制代码 <p>
再说说缺点:首先java功能强大的背后是其复杂性,就拿web来说,当今流行的框架有很多,什么struts,spring,jQuery等等,而这无疑增加了java的复杂性。 |
|