我正在尝试创建一个可以具有名称和ID值的excel文件 制作bol的行在我的程序中给了我错误。请帮助我,因为可能是错误...请 如果可能的话,还可以帮我解决只能将字符串中的名称写入excel文件的代码。
package demos;
import jxl.*;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
import java.io.*;
import java.util.*;
import com.sun.rowset.internal.Row;
import jxl.CellView;
import jxl.Workbook;
import jxl.WorkbookSettings;
import jxl.write.Label;
import jxl.write.WritableCellFormat;
import jxl.write.biff.RowsExceededException;
public class StringInp
{
public static void main(String[] args) throws IOException
{
try
{
String filename="C:\\virclipse\\input.xls";
WritableWorkbook wb=Workbook.createWorkbook(new File(filename));
//Create a blank sheet
WritableSheet sheet = wb.createSheet("Employee Data",0);
//This data needs to be written (Object[])
Map<String, Object[]> data = new TreeMap<String, Object[]>();
data.put("1", new Object[] {"ID", "NAME"});
data.put("2", new Object[] {101, "Shivany"});
data.put("3", new Object[] {102, "Nalini"});
data.put("4", new Object[] {103, "John"});
data.put("5", new Object[] {104, "Ayush"});
//Iterate over data and write to sheet
Set<String> keyset = data.keySet();
int rownum = 0;
for (String key : keyset)
{
***Row row = sheet.createRow(rownum++);***
Object [] objArr = data.get(key);
int cellnum = 0;
for (Object obj : objArr)
{
***Cell cell = row.createCell(cellnum++);***
if(obj instanceof String)
{
***cell.setCellValue((String)obj);***
}
else if(obj instanceof Integer)
{
***cell.setCellValue((Integer)obj);***
}
}
//Write the workbook in file system
FileOutputStream out = new FileOutputStream(new File("filename"));
wb.write();
wb.close();
}
}
catch(WriteException e)
{
System.out.println("there is an error");
}
}
}