简体   繁体   English

WritableSheet无法使用groovy正确创建工作表

[英]WritableSheet does not create sheet properly using groovy

Soap version used-5.0.0 使用的肥皂版本-5.0.0

I am trying to create an excel sheet and write data into it using groovy script. 我正在尝试创建一个excel工作表,并使用groovy脚本将数据写入其中。 My code is given below:- 我的代码如下:

import jxl.*;
import jxl.write.*;

WritableWorkbook wb = 
    Workbook.createWorkbook(
        newFile("/Users/anant/Downloads/GroovyTest/report.xls"));

WritableSheet sheet1 = wb.createSheet("Report Worksheet", 0);

Label label = new Label(0, 0, "hello");

sheet1.addCell(label)

Now the problems that I face are: 现在我面临的问题是:

  1. The excel sheet gets created in the given location but whenever I try to open it, it says that someone else is working on the sheet and hence I have to click either 'Read-only' or 'Notify' options excel工作表是在给定位置创建的,但是每当我尝试打开它时,它都说其他人正在工作该工作表,因此我必须单击“只读”或“通知”选项

  2. Now, I click 'Read-only' and then another message appears something like this- 'The type & extension of the sheet does not match and it is corrupted.Should you open it?'. 现在,我单击“只读”,然后出现另一条消息,例如:“工作表的类型和扩展名不匹配,它已损坏。您应该打开它吗?”。 On clicking yes, the excel sheet opens but the name of the sheet is not 'Report Worksheet' but takes the name of the excel workbook 'report' and also the "hello" text does not get entered. 单击“是”后,将打开excel工作表,但工作表的名称不是“ Report Worksheet”,而是使用excel工作簿的名称“ report”,并且也不会输入“ hello”文本。

Please suggest where am I getting wrong. 请指出我在哪里弄错了。 I tried several times but the same issue happens even in other systems as well. 我尝试了几次,但是即使在其他系统中也发生相同的问题。

After sheet1.addCell(label) sheet1.addCell(label)

You should write and close the workbook according to the doc 您应该根据文档 writeclose工作簿

wb.write()
wb.close()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM