本文整理汇总了Java中jxl.write.WritableSheet.addCell方法的典型用法代码示例。如果您正苦于以下问题:Java WritableSheet.addCell方法的具体用法?Java WritableSheet.addCell怎么用?Java WritableSheet.addCell使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jxl.write.WritableSheet
的用法示例。
在下文中一共展示了WritableSheet.addCell方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ExportTLDToXLS
import jxl.write.WritableSheet; //导入方法依赖的package包/类
public static void ExportTLDToXLS(String filename, ArrayList<Object> data) throws IOException {
try {
WritableFont titleFont = new WritableFont(WritableFont.ARIAL, 10, WritableFont.BOLD, true);
WritableCellFormat titleformat = new WritableCellFormat(titleFont);
WritableWorkbook workbook = Workbook.createWorkbook(new File(filename));
WritableSheet sheet = workbook.createSheet("TLD Expand", 0);
sheet.addCell(new Label(0, 0, "Domain name", titleformat));
sheet.addCell(new Label(1, 0, "Name server", titleformat));
sheet.addCell(new Label(2, 0, "Admin name", titleformat));
sheet.addCell(new Label(3, 0, "Registrant", titleformat));
int nextRow = 1;
Iterator i = data.iterator();
while (i.hasNext()) {
DomainResult res = (DomainResult) i.next();
sheet.addCell(new Label(0, nextRow, res.getDomainName()));
sheet.addCell(new Label(1, nextRow, res.getNameServer()));
sheet.addCell(new Label(2, nextRow, res.getAdminName()));
sheet.addCell(new Label(3, nextRow, res.getRegistrant()));
nextRow++;
}
workbook.write();
workbook.close();
} catch (WriteException ex) {
Logger.getLogger("resultExport.ExportForwardLookupsToXLS").log(Level.SEVERE, null, ex);
}
}
示例2: readExcel
import jxl.write.WritableSheet; //导入方法依赖的package包/类
public static void readExcel(String inputfileName, String outputfileName) throws BiffException, IOException , RowsExceededException, WriteException{
Workbook wb=Workbook.getWorkbook(new File(inputfileName));
Sheet sheet = wb.getSheet(0); //get sheet(0)
WritableWorkbook wwb = Workbook.createWorkbook(new File(outputfileName));
WritableSheet ws = wwb.createSheet("topicName", 0);
//traversal
for(int i=0; i<sheet.getRows(); i++)
{
String content = sheet.getCell(0,i).getContents();
String[] words = content.split("\\(");
content = words[0];
content = content.toLowerCase();
content = content.replaceAll("_", " ");
content = content.replaceAll("-", " ");
content = content.replaceAll("\\s+", " ");
if(content.contains("data structure") && !content.trim().equals("data structure"))
content = content.replaceAll("data structure", "");
Label labelC = new Label(0, i, content.trim());
ws.addCell(labelC);
}
wwb.write();
wwb.close();
}
示例3: ExportCertToXLS
import jxl.write.WritableSheet; //导入方法依赖的package包/类
public static void ExportCertToXLS(String filename, ArrayList<Object> data) throws IOException {
try {
WritableFont titleFont = new WritableFont(WritableFont.ARIAL, 10, WritableFont.BOLD, true);
WritableCellFormat titleformat = new WritableCellFormat(titleFont);
WritableWorkbook workbook = Workbook.createWorkbook(new File(filename));
WritableSheet sheet = workbook.createSheet("SSLCert CN", 0);
sheet.addCell(new Label(0, 0, "IP address", titleformat));
sheet.addCell(new Label(1, 0, "Host name", titleformat));
sheet.addCell(new Label(2, 0, "Domain name", titleformat));
int nextRow = 1;
Iterator i = data.iterator();
while (i.hasNext()) {
CertResult res = (CertResult) i.next();
sheet.addCell(new Label(0, nextRow, res.getIpAddress()));
sheet.addCell(new Label(1, nextRow, res.getHostName()));
sheet.addCell(new Label(2, nextRow, res.getDomainName()));
nextRow++;
}
workbook.write();
workbook.close();
} catch (WriteException ex) {
Logger.getLogger("resultExport.ExportForwardLookupsToXLS").log(Level.SEVERE, null, ex);
}
}
示例4: addNumberDiv1024
import jxl.write.WritableSheet; //导入方法依赖的package包/类
private void addNumberDiv1024(WritableSheet sheet, int col, int row, String s[], int index, WritableCellFormat format) throws RowsExceededException, WriteException {
if (sheet==null || s==null)
return;
if (index>=s.length)
return;
double d;
try {
d = Double.parseDouble(s[index]);
d = d / 1024;
// Only keep 2 digits: avoid rounding errors
d = 1d*(int)(d*100)/100;
sheet.addCell(new Number(col,row,d,format));
} catch (NumberFormatException nfe) {}
}
示例5: addMultipleLabelsWrap
import jxl.write.WritableSheet; //导入方法依赖的package包/类
private void addMultipleLabelsWrap(WritableSheet sheet, int col, int row, String s[], WritableCellFormat format) throws RowsExceededException, WriteException {
if (sheet==null || s==null)
return;
if (s.length==0)
return;
if (s.length==1)
sheet.addCell(new Label(col,row,s[0],format));
else {
String result = s[0];
for (int i=1; i<s.length; i++)
//result = result + ", " + s[i];
result = result + "\n" + s[i];
sheet.addCell(new Label(col,row,result,format));
}
}
示例6: addNumber
import jxl.write.WritableSheet; //导入方法依赖的package包/类
private void addNumber(WritableSheet sheet, int col, int row, String s[], int index, WritableCellFormat format) throws RowsExceededException, WriteException {
if (sheet==null || s==null)
return;
if (index>=s.length)
return;
double d;
try {
d = Double.parseDouble(s[index]);
// Only keep 2 digits: avoid rounding errors
d = 1d*(int)(d*100)/100;
sheet.addCell(new Number(col,row,d,format));
} catch (NumberFormatException nfe) {}
}
示例7: writeList
import jxl.write.WritableSheet; //导入方法依赖的package包/类
public void writeList(String[] data) throws FileNotFoundException,
IOException,
WriteException {
//Blank workbook
WritableWorkbook workbook = Workbook.createWorkbook(excelFile);
//Create a blank sheet
WritableSheet sheet = workbook.createSheet("defaut sheet", 0);
//Iterate over data and write to sheet
int rownum = 0;
for (String str : data) {
// create a colum cell
Label label0 = new Label(0, rownum, Paths.get(str).getFileName().toString());
sheet.addCell(label0);
Label label1 = new Label(1, rownum, str);
sheet.addCell(label1);
}
//Write the workbook in file system
workbook.write();
// close the file
workbook.close();
}
示例8: addCell
import jxl.write.WritableSheet; //导入方法依赖的package包/类
/**
* (导出)Excel内容填充(从第三行开始)
*
* @param Info
* @param ws
* @param format
* @param rowscount
* @throws Exception
*/
private void addCell(ExcelModel eModel, Object obj, WritableSheet ws,
WritableCellFormat format, int rowscount) throws Exception {
if (obj != null) {
int cols = 0;
ExcelColumn ec = null;
// List ecList =
// HibDb.queryHQL("from ExGroupCode ec where ec.status='A' and ec.exGroup.excel.code='"+code+"'");
int count = 0;
for (int i = 0; i < eModel.getEcList().size(); i++) {
ec = (ExcelColumn) eModel.getEcList().get(i);
// if(ec.getCols()>=0){
ws.addCell(new Label(i - count, rowscount, this.getValue(eModel, obj, ec.getCols(), ec.getCode()), format));
cols++;
// }
}
}
}
示例9: writeCell
import jxl.write.WritableSheet; //导入方法依赖的package包/类
/**
* @param columnPosition - column to place new cell in
* @param rowPosition - row to place new cell in
* @param contents - string value to place in cell
* @param headerCell - whether to give this cell special formatting
* @param sheet - WritableSheet to place cell in
* @throws RowsExceededException - thrown if adding cell exceeds .xls row limit
* @throws WriteException - Idunno, might be thrown
*/
public void writeCell(int columnPosition, int rowPosition, String contents, boolean headerCell,
WritableSheet sheet) throws RowsExceededException, WriteException{
//create a new cell with contents at position
Label newCell = new Label(columnPosition,rowPosition,contents);
if (headerCell){
//give header cells size 10 Arial bolded
WritableFont headerFont = new WritableFont(WritableFont.ARIAL, 10, WritableFont.BOLD);
WritableCellFormat headerFormat = new WritableCellFormat(headerFont);
//center align the cells' contents
headerFormat.setAlignment(Alignment.CENTRE);
newCell.setCellFormat(headerFormat);
}
sheet.addCell(newCell);
}
示例10: ExportForwardLookupsToXLS
import jxl.write.WritableSheet; //导入方法依赖的package包/类
public static void ExportForwardLookupsToXLS(String filename, List<Object> data) throws IOException {
try {
WritableFont titleFont = new WritableFont(WritableFont.ARIAL, 10, WritableFont.BOLD, true);
WritableCellFormat titleformat = new WritableCellFormat(titleFont);
WritableWorkbook workbook = Workbook.createWorkbook(new File(filename));
WritableSheet sheet = workbook.createSheet("Forward lookups", 0);
sheet.addCell(new Label(0, 0, "Domain name", titleformat));
sheet.addCell(new Label(1, 0, "Host name", titleformat));
sheet.addCell(new Label(2, 0, "IP address", titleformat));
sheet.addCell(new Label(3, 0, "Type", titleformat));
int nextRow = 1;
Iterator i = data.iterator();
while (i.hasNext()) {
ForwardLookupResult res = (ForwardLookupResult) i.next();
sheet.addCell(new Label(0, nextRow, res.getDomainName()));
sheet.addCell(new Label(1, nextRow, res.getHostName()));
sheet.addCell(new Label(2, nextRow, res.getIpAddress()));
sheet.addCell(new Label(3, nextRow, res.getLookupType()));
nextRow++;
}
workbook.write();
workbook.close();
} catch (WriteException ex) {
Logger.getLogger("resultExport.ExportForwardLookupsToXLS").log(Level.SEVERE, null, ex);
}
}
示例11: ExportReverseToXLS
import jxl.write.WritableSheet; //导入方法依赖的package包/类
public static void ExportReverseToXLS(String filename, ArrayList<Object> data) throws IOException {
try {
WritableFont titleFont = new WritableFont(WritableFont.ARIAL, 10, WritableFont.BOLD, true);
WritableCellFormat titleformat = new WritableCellFormat(titleFont);
WritableWorkbook workbook = Workbook.createWorkbook(new File(filename));
WritableSheet sheet = workbook.createSheet("Bing IP search", 0);
sheet.addCell(new Label(0, 0, "IP address", titleformat));
sheet.addCell(new Label(1, 0, "Domain name", titleformat));
sheet.addCell(new Label(2, 0, "Host name", titleformat));
int nextRow = 1;
Iterator i = data.iterator();
while (i.hasNext()) {
ReverseLookupResult res = (ReverseLookupResult) i.next();
sheet.addCell(new Label(0, nextRow, res.getIpAddress()));
sheet.addCell(new Label(1, nextRow, res.getDomainName()));
sheet.addCell(new Label(2, nextRow, res.getHostName()));
nextRow++;
}
workbook.write();
workbook.close();
} catch (WriteException ex) {
Logger.getLogger("resultExport.ExportReverseToXLS").log(Level.SEVERE, null, ex);
}
}
示例12: exportTableTo
import jxl.write.WritableSheet; //导入方法依赖的package包/类
/**
* Exports a {@link JTable} to an excel file. If the file does not exists,
* creates one.
*
* @param table table to export
* @param file destination file
* @throws IOException thrown when export can not be completed (Ex.
* FileNotFound)
*/
public static void exportTableTo(JTable table, File file) throws IOException {
try {
Logging.log("Exporting table to " + file.getPath());
Files.createNewFileWithParents(file);
WritableWorkbook workbook = Workbook.createWorkbook(file);
WritableSheet sheet = workbook.createSheet("First Sheet", 0);
TableModel model = table.getModel();
for (int i = 0; i < model.getRowCount(); i++) {
for (int j = 0; j < model.getColumnCount(); j++) {
Label cell = new Label(j, i, String.valueOf(model.getValueAt(i, j)));
sheet.addCell(cell);
}
}
workbook.write();
workbook.close();
} catch (WriteException ex) {
throw new IOException();
}
}
示例13: exportExcel
import jxl.write.WritableSheet; //导入方法依赖的package包/类
public void exportExcel() {
JFileChooser jfc = new JFileChooser(System.getProperty("user.dir"));
ExcelFileFilter eff = new ExcelFileFilter();
jfc.setFileFilter(eff);
File f=new File("dsdpTable.xls");
jfc.setSelectedFile(f);
do {
int c = jfc.showSaveDialog(null);
if (c==JFileChooser.CANCEL_OPTION||c==JFileChooser.ERROR_OPTION) return;
f = jfc.getSelectedFile();
if (f.exists()) {
c=JOptionPane.showConfirmDialog(null, "File Already Exists\nConfirm Overwrite");
if (c==JOptionPane.OK_OPTION) break;
if (c==JOptionPane.CANCEL_OPTION) return;
}
} while (f.exists());
try {
WritableWorkbook wb = Workbook.createWorkbook(f);
WritableSheet sheet = wb.createSheet("First Sheet", 0);
for (int i=0;i<table.getColumnCount();i++)
sheet.addCell( new Label(i,0,table.getColumnName(i)) );
for (int i=0;i<table.getRowCount();i++) {
for (int j=0; j<table.getColumnCount();j++) {
Object o = table.getValueAt(i, j);
if (o == null || ( o instanceof String && ((String)o).equals("NaN") ) ) o = "";
sheet.addCell( new Label(j,i+1,o.toString()) );
}
}
wb.write();
wb.close();
} catch (Exception ex){
ex.printStackTrace();
}
}
示例14: saveAsExcel
import jxl.write.WritableSheet; //导入方法依赖的package包/类
protected void saveAsExcel(Iterator it) {
JFileChooser jfc = new JFileChooser(System.getProperty("user.home"));
ExcelFileFilter eff = new ExcelFileFilter();
jfc.setFileFilter(eff);
File f=new File("PDB_Export.xls");
jfc.setSelectedFile(f);
do {
int c = jfc.showSaveDialog(null);
if (c==jfc.CANCEL_OPTION||c==jfc.ERROR_OPTION) return;
f = jfc.getSelectedFile();
if (f.exists()) {
c=JOptionPane.showConfirmDialog(null, "File Already Exists\nConfirm Overwrite");
if (c==JOptionPane.OK_OPTION) break;
if (c==JOptionPane.CANCEL_OPTION) return;
}
} while (f.exists());
try {
WritableWorkbook wb = Workbook.createWorkbook(f);
WritableSheet sheet = wb.createSheet("First Sheet", 0);
int r = 0;
while (it.hasNext()) {
String[] split = it.next().toString().split("\\t");
for (int i = 0; i < split.length; i++)
sheet.addCell( new Label(i,r,split[i]) );
r++;
}
wb.write();
wb.close();
} catch (Exception ex){
}
}
示例15: createIndex
import jxl.write.WritableSheet; //导入方法依赖的package包/类
/**
* Create the index worksheet.
*
* <p>This also creates links back to the index in each of the worksheets.</p>
*/
public void createIndex() {
WritableSheet sheet = workbook.createSheet(spreadsheetifyName("Index"), 0);
createTitle(sheet, "Index");
try {
// Create links for each worksheet, apart from the first sheet which is the
// index we're currently creating
final String[] names = workbook.getSheetNames();
for (int currentSheet = 1; currentSheet < names.length; currentSheet++) {
// Create the link from the index to the table's worksheet
WritableHyperlink link = new WritableHyperlink(0, currentSheet - 1 + NUMBER_OF_ROWS_IN_TITLE, names[currentSheet], workbook.getSheet(currentSheet), 0, 0);
sheet.addHyperlink(link);
//Add the filename in column B (stored in cell B2 of each sheet)
String fileName = workbook.getSheet(currentSheet).getCell(1, 1).getContents();
Label fileNameLabel = new Label(1, currentSheet - 1 + NUMBER_OF_ROWS_IN_TITLE, fileName);
WritableFont fileNameFont = new WritableFont(WritableFont.ARIAL,10,WritableFont.NO_BOLD,false,UnderlineStyle.NO_UNDERLINE,Colour.BLACK);
WritableCellFormat fileNameFormat = new WritableCellFormat(fileNameFont);
fileNameLabel.setCellFormat(fileNameFormat);
sheet.addCell(fileNameLabel);
// Create the link back to the index
link = new WritableHyperlink(0, 1, "Back to index", sheet, 0, currentSheet + NUMBER_OF_ROWS_IN_TITLE - 1);
workbook.getSheet(currentSheet).addHyperlink(link);
//Set column A of each sheet to be wide enough to show "Back to index"
workbook.getSheet(currentSheet).setColumnView(0, 13);
}
// Make Column A fairly wide to show tab names and hide column B
sheet.setColumnView(0, 35);
sheet.setColumnView(1, 0);
} catch (Exception e) {
throw new RuntimeException(e);
}
}