我想创建一个Excel文件并写入数据,就像用Java写入文本文件一样。我尝试更改文件扩展名.txt
to .xls
。但我想将 Excel 文件中的字母加粗。我怎样才能做到这一点?
我尝试过使用 JXL API,但每次我必须创建标签时我都不想添加任何标签。无法编辑表格的行和列吗?
//Find jar from here "http://poi.apache.org/download.html"
import java.io.*;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.usermodel.HSSFRow;
public class CreateExlFile{
public static void main(String[]args) {
try {
String filename = "C:/NewExcelFile.xls" ;
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet("FirstSheet");
HSSFRow rowhead = sheet.createRow((short)0);
rowhead.createCell(0).setCellValue("No.");
rowhead.createCell(1).setCellValue("Name");
rowhead.createCell(2).setCellValue("Address");
rowhead.createCell(3).setCellValue("Email");
HSSFRow row = sheet.createRow((short)1);
row.createCell(0).setCellValue("1");
row.createCell(1).setCellValue("Sankumarsingh");
row.createCell(2).setCellValue("India");
row.createCell(3).setCellValue("[email protected] /cdn-cgi/l/email-protection");
FileOutputStream fileOut = new FileOutputStream(filename);
workbook.write(fileOut);
fileOut.close();
workbook.close();
System.out.println("Your excel file has been generated!");
} catch ( Exception ex ) {
System.out.println(ex);
}
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)