gpt4 book ai didi

java - OleFrame 无法保存 Excel 文件

转载 作者:搜寻专家 更新时间:2023-11-01 03:56:43 25 4
gpt4 key购买 nike

我设置了一个带有 OLE 框架的应用程序以进行就地编辑。 Word 文件一切正常,但保存 Excel 不起作用。 Excel 应用程序的保存按钮要么变灰(我想当非 OLE 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);
}
}

最佳答案

Save Excel Files using 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();
}
}
}

关于java - OleFrame 无法保存 Excel 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24647613/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com