请各位帮帮我!!!!

解决方案 »

  1.   

    有个直接读取与导出excel的包,我忘记名字了,在公司有用过,如果楼主明天还没有解决此问题,我传给你
      

  2.   

    使用bufferWriter写出文件但在写出之前设计好它的扩展名为.xls当然里面的数据间隔要用/t来表示这一个数据和下一个不是在同一个单元格里
      

  3.   

    用jxl.jar这个包,百度可以找到,找不到给我发短消息,例子
    package infon.util;import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.io.InputStream;import jxl.Cell;
    import jxl.Sheet;
    import jxl.Workbook;
    import jxl.read.biff.BiffException;public class ReadExcel {
    public void InputExcel(String path) {
    try {
    InputStream is = new FileInputStream(path);
    Workbook wb = Workbook.getWorkbook(is);
    int sheetCount = wb.getNumberOfSheets();
    System.out.println("count of page:" + sheetCount);
    for (int s = 0; s < sheetCount; s++) {
    Sheet st = wb.getSheet(s);
    int column = st.getColumns();
    int row = st.getRows();
    System.out.println("page name:" + st.getName() + "\n column:"
    + column + "\n row:" + row);
    Cell cell = null;
    for (int m = 0; m < column; m++) {
    for (int n = 0; n < row; n++) {
    cell = st.getCell(m, n);
    System.out.print(cell.getContents() + "");
    }
    System.out.println();
    }
    }
    wb.close();
    is.close();
    } catch (FileNotFoundException e) {
    e.printStackTrace();
    } catch (BiffException e) {
    e.printStackTrace();
    } catch (IOException e) {
    e.printStackTrace();
    }
    } public static void main(String[] args) {
    new ReadExcel()
    .InputExcel("src/andy/lian/excel/YICT_FIX_project_schedule.xls");
    }
    }
      

  4.   

    1通过sql语句可以倒
    2通过程序代码也可以。例如楼上 infon(阿槑) 的。
      

  5.   

    jxl.jar
    网上很多``去下一个
      

  6.   

    jxl.jar工具就可以了:例子如下:import java.io.*;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    import java.util.Vector;
    import javax.servlet.ServletException;
    import javax.servlet.http.*;
    import jxl.SheetSettings;
    import jxl.Workbook;
    import jxl.format.*;
    import jxl.write.*;public class PrinterServlet extends HttpServlet
    {    private static final String CONTENT_TYPE = "text/html; charset=GBK";    public PrinterServlet()
        {
        }    public void init()
            throws ServletException
        {
        }    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException
        {
            response.setContentType("text/html; charset=GBK");
            PrintWriter out = response.getWriter();
            boolean bExportSucc = false;
            String sErrorStr = "";
            String sHead = "/files/";
            String sFileName = "Test.xls";
            String sCurrPath = request.getRealPath("/files/");
            File filepath = new File(sCurrPath);
            if(filepath.exists())
                out.println("路径已经存在!<br>");
            else
                filepath.mkdir();
            sCurrPath = sCurrPath + "/" + sFileName;
            File file = new File(sCurrPath);
            file.createNewFile();
            String sUrlPath = sHead + sFileName;
            try
            {
                WritableWorkbook workbook = Workbook.createWorkbook(new File(sCurrPath));
                WritableSheet sheet = workbook.createSheet("****信息管理系统", 0);
                SheetSettings sheetset = sheet.getSettings();
                sheetset.setProtected(false);
                WritableFont NormalFont = new WritableFont(WritableFont.ARIAL, 10);
                WritableFont BoldFont = new WritableFont(WritableFont.ARIAL, 14, WritableFont.BOLD);
                WritableCellFormat wcf_left = new WritableCellFormat(NormalFont);
                wcf_left.setBorder(jxl.format.Border.NONE, jxl.format.BorderLineStyle.THIN);
                wcf_left.setVerticalAlignment(jxl.format.VerticalAlignment.TOP);
                wcf_left.setAlignment(jxl.format.Alignment.LEFT);
                wcf_left.setWrap(false);
                WritableCellFormat wcf_right = new WritableCellFormat(NormalFont);
                wcf_right.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN);
                wcf_right.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);
                wcf_right.setAlignment(jxl.format.Alignment.RIGHT);
                wcf_right.setWrap(false);
                WritableCellFormat wcf_center = new WritableCellFormat(NormalFont);
                wcf_center.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN);
                wcf_center.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);
                wcf_center.setAlignment(jxl.format.Alignment.CENTRE);
                wcf_center.setWrap(false);
                WritableCellFormat wcf_merge = new WritableCellFormat(BoldFont);
                wcf_merge.setBorder(jxl.format.Border.NONE, jxl.format.BorderLineStyle.THICK);
                wcf_merge.setVerticalAlignment(jxl.format.VerticalAlignment.TOP);
                wcf_merge.setAlignment(jxl.format.Alignment.CENTRE);
                wcf_merge.setWrap(true);
                HttpSession session = request.getSession(true);
                Vector print = (Vector)session.getAttribute("aa");
                String temp[][] = (String[][])print.get(0);
                String vBT = (String)print.get(1);
                String vXM = (String)print.get(2);
                int chang = Integer.parseInt(print.get(3).toString()) - 1;
                String strSPR = (String)print.get(4);
                Date systempDate = new Date();
                SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                String sysDate = format.format(systempDate);
                sheet.mergeCells(0, 0, chang, 2);
                sheet.addCell(new Label(0, 0, vBT, wcf_merge));
                sheet.mergeCells(0, 3, chang, 3);
                sheet.addCell(new Label(0, 3, "打印操作员:" + vXM, wcf_left));
                sheet.mergeCells(0, 4, chang, 4);
                sheet.addCell(new Label(0, 4, "打印时 间:" + sysDate, wcf_left));
                sheet.mergeCells(0, 5, chang, 5);
                sheet.addCell(new Label(0, 5, "审批 状态:" + strSPR, wcf_left));
                for(int m = 0; m < temp.length; m++)
                {
                    for(int n = 0; n < temp[m].length; n++)
                        sheet.addCell(new Label(n, m + 7, temp[m][n].replaceAll("\"", "").trim(), wcf_center));            }            workbook.write();
                workbook.close();
                bExportSucc = true;
            }
            catch(Exception e)
            {
                e.printStackTrace();
                sErrorStr = e.toString();
                System.out.println("在输出到EXCEL的过程中出现错误,错误原因:" + e.toString());
            }
            out.println("<html>");
            out.println("<head>");
            out.println("<title>******EXCEL输出</title>");
            out.println("</head><body><br>");
            out.println("<div align=center>");
            if(bExportSucc)
                out.println("<meta http-equiv=refresh content=\"1;url=" + sUrlPath + "\">");
            else
                out.println("<font color=red>在输出到EXCEL文件的过程中发生错误,错误原因:" + sErrorStr + "</font>");
            out.println("</div></body></html>");
        }    public void destroy()
        {
        }
    }
    导出文件的格式(当然你可以定义你自己的格式):
      
           员工帐号报表


    打印操作员:Admin
    打印时 间:2007-05-10 09:34:32 帐号编号 用户名   密 码 email          用户状态 员工编号
    1 test1 test [email protected] 1 1
    2 test2 test     [email protected] 1 2
    3 test3 test     [email protected] 1 3
      

  7.   

    一个导入到EXCEL的工具,不防一试SQL导出到EXCEL http://www.onlinedown.net/soft/44040.htm