cvs生成
第一 分割符号为逗号
2, 必须考虑其中包含逗号,“等特殊字符
3,必须考虑其中包含换行的因素
希望大家给一个好的cvs写入的例子
谢谢大家了
------解决方案--------------------对逗号用自定义的标签进行转义存储,读取SPLIT后再替换。
换行不用考虑,直接该怎样就怎样。读取时全文读入,用逗号SPLIT,换行毫无问题。
------解决方案--------------------
你说的应该是 CSV 吧,不是 CVS 哦,呵呵。
http://sourceforge.net/projects/javacsv/
------解决方案--------------------cvs版本控制器
------解决方案--------------------package com.qam.project.bjds.pda.export;
import java.io.*;
import java.sql.ResultSet;
import
java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Properties;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import au.com.bytecode.opencsv.CSVWriter;
import com.qam.framework.QamFrameworkException;
import com.qam.framework.context.ApplicationConfig;
import com.qam.framework.extension.component.impl.AbstractComponent;
import com.qam.framework.util.CommonUtils;
import com.qam.project.bjds.gongyong.ShuXingCX;
public class ExportPDA extends AbstractComponent {
/**
*
*/
private static final long serialVersionUID = 1L;
private static final Log log = LogFactory.getLog(ExportPDA.class);
private static String str_PROPERTIESPATH=""; //读取属性文件的路径
private static final String PROPERTIES_NAME="ggcw.properties"; //属性文件的名称
public void exportPDA(List values) throws Exception {
this.values = values;
String jigoubh="";
String xiangmufl="";
String pandianzt="";
String niandu="";
Object obj;
this.values=values;
obj=this.getValue("JiGouBH");
if(obj!=null)
{
jigoubh=obj.toString();
}
//取机构编号
obj=this.getValue("FenLeiBH");
if(obj!=null)
{
xiangmufl=obj.toString();
}
//取分类编号
obj=this.getValue("PanDianZT");
if(obj!=null)
{
pandianzt=obj.toString();
}
//盘点状态
obj=this.getValue("NianDu");
if(obj!=null)
{
niandu=obj.toString();
}
//年度
SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");//设置日期格式
String sql="SELECT DISTINCT "+
" zc.yewubm as zc_yewubm, "+
" zc.mingcheng as zc_mingcheng, "+
" jg.mingcheng as shiyoubm , " +
" zc.suoshuzcfl as flbh, " +
" zc.suoshurkqd as rkq, " +
" to_char(zc.gouzhirq, 'yyyy-mm-dd ') as zc_gouzhirq, "+
" cfdd.mingcheng as cfdd_mingcheng "+
" FROM zc_zichanbt zc, "+
" zc_cundangdd cfdd, "+
" zc_zichanfl zcfl, "+
" jc_jigou jg "+
" WHERE 1 = 1 "+
" AND zc.cunfangdd = cfdd.bianhao(+) "+
" AND zc.suoshuzcfl = zcfl.bianhao "+
" and jg.bianhao=zc.shiyongbm ";
if(jigoubh!=null && jigoubh.length()>0)
{
sql+=" AND zc.shiyongbm IN ('"+jigoubh+"') ";
}
if(xiangmufl!=null && xiangmufl.length()>0)
{
sql+= " and zc.suoshuzcf