为什么我的代码不能修改Excel文件的每一行呢?请大家帮我看看,谢谢
public CheckbackCopyright(String excelUrl) {
if (this.workbook == null) {
try {
InputStream inputStream = new FileInputStream(excelUrl);
this.workbook = Workbook.getWorkbook(inputStream);
this.excelUrl = excelUrl;
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
// 查询Excel工作表的每一行,并且返回歌手和歌曲
public void getColourringInfo() {
sheet = workbook.getSheet(0);
int rows = sheet.getRows();
int columns = sheet.getColumns();
for (int line = 1; line < rows; line++) {
for (int c = 0; c < columns; c++) {
Cell cell = sheet.getCell(c, line);
if (c == 0)
singer = cell.getContents().trim();
if (c == 1)
song = cell.getContents().trim();
}
executeQuery(line, singer, song);
}
}
// 按歌曲和歌手查询彩铃信息
public void executeQuery(int line, String singer, String song) {
String sql = "select * from COLOURRING where SINGER='" + singer
+ "' and SONG like'" + song + "%' and RING='2'";
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
try {
con = DatabaseConnection.getConnection();
stmt = con.createStatement();
rs = stmt.executeQuery(sql);
if (rs.next()) {
addCopyrightAndUsefullife(line,rs.getString(4),rs.getString(5));
} else {
System.out.println(line + "," + singer + "," + song
+ ":没有找到本首彩铃的版权信息");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
DatabaseConnection.close(rs);
DatabaseConnection.close(con, stmt);
}
}
// 更新歌曲列表,即加上所属版权和有限期
public void addCopyrightAndUsefullife(int line, String copyright,
String usefullife) {
try {
WritableWorkbook wwb = Workbook.createWorkbook(new File(excelUrl),workbook);
WritableSheet ws = wwb.getSheet(0);
Label label1 = new Label(3, line, copyright);
ws.addCell(label1);
Label label2 = new Label(4, line, usefullife);
ws.addCell(label2);
wwb.write();
wwb.close();
} catch (IOException ioe) {
ioe.printStackTrace();
} catch (WriteException we) {
we.printStackTrace();
}
}
代码执行后始终只能修改到最后一行,请问是怎么回事,解决了马上给分!
if (this.workbook == null) {
try {
InputStream inputStream = new FileInputStream(excelUrl);
this.workbook = Workbook.getWorkbook(inputStream);
this.excelUrl = excelUrl;
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
// 查询Excel工作表的每一行,并且返回歌手和歌曲
public void getColourringInfo() {
sheet = workbook.getSheet(0);
int rows = sheet.getRows();
int columns = sheet.getColumns();
for (int line = 1; line < rows; line++) {
for (int c = 0; c < columns; c++) {
Cell cell = sheet.getCell(c, line);
if (c == 0)
singer = cell.getContents().trim();
if (c == 1)
song = cell.getContents().trim();
}
executeQuery(line, singer, song);
}
}
// 按歌曲和歌手查询彩铃信息
public void executeQuery(int line, String singer, String song) {
String sql = "select * from COLOURRING where SINGER='" + singer
+ "' and SONG like'" + song + "%' and RING='2'";
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
try {
con = DatabaseConnection.getConnection();
stmt = con.createStatement();
rs = stmt.executeQuery(sql);
if (rs.next()) {
addCopyrightAndUsefullife(line,rs.getString(4),rs.getString(5));
} else {
System.out.println(line + "," + singer + "," + song
+ ":没有找到本首彩铃的版权信息");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
DatabaseConnection.close(rs);
DatabaseConnection.close(con, stmt);
}
}
// 更新歌曲列表,即加上所属版权和有限期
public void addCopyrightAndUsefullife(int line, String copyright,
String usefullife) {
try {
WritableWorkbook wwb = Workbook.createWorkbook(new File(excelUrl),workbook);
WritableSheet ws = wwb.getSheet(0);
Label label1 = new Label(3, line, copyright);
ws.addCell(label1);
Label label2 = new Label(4, line, usefullife);
ws.addCell(label2);
wwb.write();
wwb.close();
} catch (IOException ioe) {
ioe.printStackTrace();
} catch (WriteException we) {
we.printStackTrace();
}
}
代码执行后始终只能修改到最后一行,请问是怎么回事,解决了马上给分!
...全文
相关推荐
利用EXCEL批量修改文件名字
利用EXCEL批量修改文件名字;方便、快捷
MetaMask_v3.9.5以太坊钱包管理插件使用指南
MetaMask是一种流行的浏览器扩展程序,作为以太坊钱包,它允许用户与以太坊区块链及其去中心化应用(DApps)进行交互。MetaMask不仅为用户提供了一个便捷的界面来管理他们的以太坊账户和数字资产,而且还充当了网页与以太坊网络之间的桥梁。在某些情况下,用户可能会收到一些非主流或新发行的代币,这时他们需要手动添加这些代币到MetaMask中以查看其余额。添加自定义代币步骤:打开MetaMask插件,并确保你已经连接到了相应的网络。
Pandas读取并修改excel的示例代码
主要介绍了Pandas读取并修改excel的示例代码,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
如何让excel文件只能查看不能被修改?.docx
如何让excel文件只能查看不能被修改?.docx
EXCEL文件双击不能直接打开的解决办法
EXCEL文件双击不能直接打开的解决办法


Java SE
