java导出excel 如何处理字段值为空的不显示

 我来答
kfjchvq
2011-06-19 · TA获得超过1964个赞
知道小有建树答主
回答量:1586
采纳率:0%
帮助的人:787万
展开全部
用这个方式占用内存比较小,不过不能控制excel格式
public class Excel {
public static void main(String[] args) {
try {
String url = "jdbc:oracle:thin:@10.20.1.23:1521:ilisdev";
String username = "uu";
String password = "pp";
Connection conn;
Statement stmt;
ResultSet rs;
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection(url, username, password);
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
String sql = "select a.appntname,c.riskname,b.name from lcpol a,ldcom b,lmrisk c "
+ "where a.managecom=b.comcode and a.riskcode = c.riskcode";
rs = stmt.executeQuery(sql);

String path = "c:/test.txt";// 数据存放的位置
Excel excel = new Excel(path, new String[] );

excel.makeXLS(rs, 3);
} catch (Exception e) {
e.printStackTrace();
}
}

private BufferedWriter buff = null;

public Excel(String filePath, String[] titles) {
try {
if (filePath == null || filePath.equals("") || titles == null
|| titles.length == 0) {
System.out.println("路径或标题为空!");
} else {
buff = new BufferedWriter(new FileWriter(filePath));
for (int i = 0; i < titles.length; i++) {
buff.write(titles[i] + "\t");
if (i == (titles.length - 1))
buff.write("\r\n");
}
}
} catch (Exception e) {
e.printStackTrace();
}
}

public void makeXLS(ResultSet rs, int colNum) {
try {
while (rs.next()) {
for (int i = 1; i <= colNum; i++) {
buff.write(rs.getString(i) + "\t");
if (i == colNum) {
buff.write("\r\n");
}
}
}
buff.close();
} catch (Exception e) {
e.printStackTrace();
}

}
}
本回答被提问者和网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
wxj1115
2011-06-16 · TA获得超过135个赞
知道小有建树答主
回答量:223
采纳率:0%
帮助的人:148万
展开全部
if(obj[m] != null) {
cell.setCellValue(obj[m].toString());
}else {
cell.setCellValue("");
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
sanddreams
2011-06-29 · 超过31用户采纳过TA的回答
知道答主
回答量:109
采纳率:0%
帮助的人:99.3万
展开全部
count为字段
在向excel中插入数据时 在SQl中使用nvl(count,0) 将count字段在为空情况下显示0 这样存入excel中的字段也为0
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
菲翠
2011-06-16
知道答主
回答量:20
采纳率:0%
帮助的人:0
展开全部
写判断啊。你的代码是SubString追加的那种吗??
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
收起 更多回答(2)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式