我正在将GWT用于项目。在按钮上单击我想将Excel文件保存到用户定义的文件位置。是否可以提示用户将文件位置保存到?
所以不要保存在C:\ New文件夹\我希望用户选择..
FileOutputStream out = new FileOutputStream("C:\\New folder\\purchase-order.xlsx");
wb.write(out);
out.close();
涉及按钮的前端看起来像这样。
Button getPurchaseOrderForAllPickedItems = new Button("Get Purchase Order for all items selected", new ClickHandler() {
public void onClick(ClickEvent event) {
HashMap<String, ArrayList<Item>> exportFile = extracted();
sendListToServerForExport(exportFile);
}
sendListToServerForExport方法如下所示:
private void sendListToServerForExport(HashMap<String, ArrayList<Item>> exportMap) {
if (stockPriceSvc == null) {
stockPriceSvc = GWT.create(PurchaseOrderService.class);
}
AsyncCallback<String> callback = new AsyncCallback<String>() {
@Override
public void onFailure(Throwable caught) {
// TODO Auto-generated method stub
}
@Override
public void onSuccess(String result) {
Window.alert(result);
}
};
stockPriceSvc.createExcelExportFile(exportMap, callback);
}
服务实现中的方法如下所示:
public String createExcelExportFile(
HashMap<String, ArrayList<Item>> exportMap) {
controller.createFileToExport(exportMap);
return "Succes";
}
答案 0 :(得分:0)
除非你要留下一些重要的细节,否则它应该非常简单。只需提示用户输入位置并使用扫描仪或提示将输入作为字符串。我会在一分钟内发布一些示例代码......
import java.util.Scanner;
public class ReadConsoleScanner {
public static void main(String[] args) {
System.out.println("Enter something here : ");
String sWhatever;
Scanner scanIn = new Scanner(System.in);
sWhatever = scanIn.nextLine();
scanIn.close();
System.out.println(sWhatever);
}
}