1

excel当用户按以下方式单击屏幕上的图标时,我正在尝试将从 DB 获取的数据导出到 Excel 工作表。它实际上工作正常,但只是想对此有更好的了解,而不是读取缓冲数据。

private void exportLayout(String date,
         PrintWriter prn,
         BufferedReader in ) throws Exception
    {
        String line = null; // Indicates current line
        boolean isNotEndofBuffer = true; // boolean to indicate if the end of buffer is reached
        boolean skip = false; // boolean to indicate if we can skip reading the current line

        try
        {
            while (isNotEndofBuffer)
            {
                if (!skip)
                {
                    line =  in.readLine();                  
                }
                if (line != null)
                {
                     ...

                     ExportUtil.outputLine(prn, TEXT1 +
                TEXT2 + TAB +
             TEXT3 + TAB );


catch( IOException ioe )
        {
            ioe.printStackTrace();
            throw ioe;
        }
        catch( Exception ex )
        {
            ex.printStackTrace();
            throw ex;

        }
4

1 回答 1

1

不需要任何代码,通过使用此查询,您可以将数据库表导出到 excel

将数据从 MySQL 导出为 CSV 文件,使用此查询很简单。

   SELECT * INTO OUTFILE '/tmp/name.csv'
   FIELDS TERMINATED BY ','
   OPTIONALLY ENCLOSED BY '"'
   ESCAPED BY '\\'
   LINES TERMINATED BY '\n'
   FROM [tablename]
于 2013-06-20T10:06:09.820 回答