2014-07-09 69 views
4

我設置了一個應用程序與OLE框就地編輯。所有的Word文件都適用,但保存Excel不起作用。 Excel應用程序的保存按鈕是灰色的(我猜當非OLE Excel仍處於打開狀態時)或者它沒有變灰,它會顯示「刷新」(德語,但仍然)並且不保存。沒有任何錯誤信息會被顯示。OleFrame無法保存Excel文件

OleControlSite#save(File, boolean)有效,但我們無法向客戶解釋他們爲什麼不能點擊Excel保存按鈕,所以我們需要以某種方式修復它。

一個小演示,重現該問題:

public class OleDemoDialog extends Dialog { 

public static void main(String[] args) { 
    OleDemoDialog dialog = new OleDemoDialog(new Shell()); 
    dialog.open(); 
} 

protected OleDemoDialog(Shell parentShell) { 
    super(parentShell); 
    setShellStyle(getShellStyle()| SWT.SHELL_TRIM); 
} 

@Override 
protected Control createDialogArea(Composite parent) { 
    OleFrame oleFrame = new OleFrame(parent, SWT.CLIP_CHILDREN); 
    oleFrame.setBackground(JFaceColors.getBannerBackground(parent 
      .getDisplay())); 
    oleFrame.setLayoutData(new GridData(GridData.FILL_BOTH)); 

    OleControlSite oleControlSite = new OleControlSite(oleFrame, SWT.NONE, 
      new File("Mappe1.xlsx")); 
    oleControlSite.doVerb(OLE.OLEIVERB_INPLACEACTIVATE); 

    return oleFrame; 
} 

@Override 
protected Point getInitialSize() { 
    return new Point(600, 600); 
} 
} 
+0

您是否看到過:http://www.aspose.com/docs/display/slidesnet/Working+with+OLE+Object+Frames? – HellBaby

+0

@HellBaby我現在做了,但是我沒有看到我描述的錯誤。 –

回答

-1

保存Excel文件使用OleFrame。

OleClientSite clientSite.save(new File("D:\\JavaBooks.xlsx"), true); 

我希望這個例子是非常有用的。

import java.io.*; 
import org.eclipse.swt.*; 
import org.eclipse.swt.events.*; 
import org.eclipse.swt.layout.*; 
import org.eclipse.swt.ole.win32.*; 
import org.eclipse.swt.widgets.*; 

public class OleDemoDialog { 

    OleClientSite clientSite; 
    OleFrame oleFrame; 

    public static void main(String[] args) { 
     Display display = new Display(); 
     OleDemoDialog example = new OleDemoDialog(); 
     example.open(display); 
    } 

    public void open(Display display) { 
     Shell shell = new Shell(display); 
     shell.setText("OleDemoDialog Example"); 
     shell.setLayout(new FillLayout()); 

     Composite parent = new Composite(shell, SWT.NONE); 
     parent.setLayout(new GridLayout(4, true)); 

     Composite buttons = new Composite(parent, SWT.NONE); 
     buttons.setLayout(new GridLayout()); 
     GridData gridData = new GridData(SWT.BEGINNING, SWT.FILL, false, false); 
     buttons.setLayoutData(gridData); 

     Composite displayArea = new Composite(parent, SWT.BORDER); 
     displayArea.setLayout(new FillLayout()); 
     displayArea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1)); 

     Button openButton = new Button(buttons, SWT.NONE); 
     openButton.setText("Open file"); 
     openButton.addSelectionListener(new SelectionAdapter() { 
      public void widgetSelected(SelectionEvent e) { 
       //new File("your File_Path.xlsx ") 
       try { 
        clientSite = new OleClientSite(oleFrame, SWT.NONE, "Excel.Sheet", new File("D:\\JavaBooks.xlsx")); 
       } catch (SWTException error) {error.printStackTrace();} 
       if (clientSite != null) 
        clientSite.doVerb(OLE.OLEIVERB_INPLACEACTIVATE); 
      } 
     }); 
     new Label(buttons, SWT.NONE); 

     Button excelButton = new Button(buttons, SWT.NONE); 
     excelButton.setText("Save"); 
     excelButton.addSelectionListener(new SelectionAdapter() { 
      public void widgetSelected(SelectionEvent e) { 

       clientSite.save(new File("D:\\JavaBooks.xlsx"), true); 
       System.out.println("save.."); 
      } 
     }); 

     oleFrame = new OleFrame(displayArea, SWT.NONE); 
     shell.setSize(800, 600); 
     shell.open(); 

     while (!shell.isDisposed()) { 
      if (!display.readAndDispatch()) 
       display.sleep(); 
     } 
    } 
} 
+0

這並沒有解決問題。 –

+0

@Steffi S.不滿足於這個答案... –