当用户按照以下方式点击屏幕上的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;
}
答案 0 :(得分:1)
不需要任何代码,通过使用此查询,您可以将数据库表导出为excel
将数据从MySQL导出到CSV文件中,使用此查询很简单。
SELECT * INTO OUTFILE '/tmp/name.csv'
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
ESCAPED BY '\\'
LINES TERMINATED BY '\n'
FROM [tablename]