![]() |
Модераторы: LSD, AntonSaburov |
![]() ![]() ![]() |
|
dumdum |
|
|||
Новичок Профиль Группа: Участник Сообщений: 2 Регистрация: 26.7.2011 Репутация: нет Всего: нет |
Когда на сайте пытаюсь сохранить файл с данными которые он вывел (табличка), то в файле экселевском тупо в ячейке записано "deleteMe" и всё, помогите, в чём ошибка?
/* * Created on 26.12.2009 */ package ru.bpc.svfe.view.cashmanagement; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.GregorianCalendar; import java.util.List; import java.util.Locale; import java.util.ResourceBundle; import javax.faces.context.FacesContext; import javax.servlet.http.HttpServletResponse; import org.ajax4jsf.model.DataVisitor; import org.apache.log4j.Logger; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFCellStyle; import org.apache.poi.hssf.usermodel.HSSFFont; import org.apache.poi.hssf.usermodel.HSSFRichTextString; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.util.HSSFColor; import ru.bpc.items.cashmanagement.AtmIncassationListItem; import ru.bpc.items.cashmanagement.IncassListFilter; import ru.bpc.jsf.auxil.SessionWrapper; import ru.bpc.jsf.utils.FacesContextUtils; import ru.bpc.svfe.logic.cashmanagement.LcCashManagement; import org.richfaces.component.UIDataTable; /** * @author Kesler Julia */ public class MbAtmIncassationList { private List<AtmIncassationListItem> atmIncassationDataTable;//таблица результатов private IncassListFilter filter;//Фильтр(ввод пользователя) private UIDataTable uiDataTable; private ResourceBundle localizedMessages_com; private ResourceBundle localizedMessages_ind; private String uid; private final static Logger _logger = Logger.getLogger( "ATM_MONITORING" ); //Конструктор public MbAtmIncassationList() { uid = SessionWrapper.getUid(); } //ГетФильтр public IncassListFilter getFilter() { if (filter == null) filter = new IncassListFilter(); return filter; } //Сетфильтр public void setFilter(IncassListFilter filter){ this.filter=filter; } public List<AtmIncassationListItem> getAtmIncassationDataTable() { if (atmIncassationDataTable == null) atmIncassationDataTable = new ArrayList<AtmIncassationListItem>(); return atmIncassationDataTable; } public void setAtmIncassationDataTable(List<AtmIncassationListItem> temp){ this.atmIncassationDataTable=temp; } //обработчик кнопки SHOW public void showButtonAction() { try { setAtmIncassationDataTable(LcCashManagement.getInstance().getAtmIncassationList( uid, getFilter())); } catch (Exception e) { _logger.error("",e); FacesContextUtils.addErrorExceptionMessage(e); } if (getAtmIncassationDataTable() == null){ List<AtmIncassationListItem> temp = new ArrayList<AtmIncassationListItem>(); this.setAtmIncassationDataTable(temp); } } // public List<AtmIncassationListItem> getFilteredData() throws IOException { final List<AtmIncassationListItem> filteredData = new ArrayList<AtmIncassationListItem>(); getUiDataTable().walk(FacesContext.getCurrentInstance(), new DataVisitor() { public void process(FacesContext context, Object rowKey, Object argument) { UIDataTable table = (UIDataTable) argument; table.setRowIndex((Integer)rowKey); AtmIncassationListItem obj = (AtmIncassationListItem) table.getRowData(); filteredData.add(obj); } }, getUiDataTable()); return filteredData; } public void setUiDataTable(UIDataTable uiDataTable) { this.uiDataTable = uiDataTable; } public UIDataTable getUiDataTable() { return uiDataTable; } //Выгрузка в Excel private String getFilename(String reportAlias, String ext) { StringBuffer result = new StringBuffer(reportAlias); final SimpleDateFormat fileDateTimeFormat = new SimpleDateFormat("yyyyMMdd"); result.append('_'); synchronized (fileDateTimeFormat) { result.append(fileDateTimeFormat.format(GregorianCalendar.getInstance().getTime())); } result.append(".").append(ext); return result.toString(); } private void insertInformAndHeader(AtmIncassationListItem item, HSSFSheet sheet, HSSFFont font, HSSFCellStyle cellStyle,HSSFRow row){ HSSFRichTextString colVal = new HSSFRichTextString(localizedMessages_com.getString("pid")); HSSFRow row1 = sheet.createRow((short)0); HSSFCell cell = row1.createCell(0); colVal.applyFont(font); cell.setCellValue(colVal); cell.setCellStyle(cellStyle); cell = row1.createCell(1); colVal = new HSSFRichTextString(localizedMessages_com.getString("address")); colVal.applyFont(font); cell.setCellValue(colVal); cell.setCellStyle(cellStyle); cell = row1.createCell(2); colVal = new HSSFRichTextString(localizedMessages_com.getString("currency")); colVal.applyFont(font); cell.setCellValue(colVal); cell.setCellStyle(cellStyle); cell = row1.createCell(3); colVal = new HSSFRichTextString(localizedMessages_ind.getString("nominal")); colVal.applyFont(font); cell.setCellValue(colVal); cell.setCellStyle(cellStyle); cell = row1.createCell(4); colVal = new HSSFRichTextString(localizedMessages_ind.getString("amount")); colVal.applyFont(font); cell.setCellValue(colVal); cell.setCellStyle(cellStyle); cell = row1.createCell(5); colVal = new HSSFRichTextString(localizedMessages_ind.getString("notes_number")); colVal.applyFont(font); cell.setCellValue(colVal); cell.setCellStyle(cellStyle); cell = row1.createCell(6); colVal = new HSSFRichTextString(localizedMessages_ind.getString("date")); colVal.applyFont(font); cell.setCellValue(colVal); cell.setCellStyle(cellStyle); } private void insertData(HSSFRow row,HSSFSheet sheet, AtmIncassationListItem item, HSSFCellStyle styleCenter, HSSFCellStyle styleRight){ HSSFCell cell = row.createCell(0); HSSFRichTextString colVal = new HSSFRichTextString(item.getPid()); cell.setCellType(HSSFCell.CELL_TYPE_STRING); cell.setCellStyle(styleCenter); cell.setCellValue(colVal); cell = row.createCell(1); colVal = new HSSFRichTextString(item.getAdress()); cell.setCellType(HSSFCell.CELL_TYPE_STRING); cell.setCellStyle(styleCenter); cell.setCellValue(colVal); cell = row.createCell(2); colVal = new HSSFRichTextString(String.valueOf(item.getValuta())); cell.setCellType(HSSFCell.CELL_TYPE_STRING); cell.setCellStyle(styleCenter); cell.setCellValue(colVal); cell = row.createCell(3); cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); cell.setCellStyle(styleCenter); cell.setCellValue(item.getNominal()); cell = row.createCell(4); cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); cell.setCellStyle(styleRight); cell.setCellValue(item.getKol()); cell = row.createCell(5); cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); cell.setCellStyle(styleRight); cell.setCellValue(Integer.parseInt(item.getFlag2())); cell = row.createCell(6); colVal = new HSSFRichTextString(String.valueOf(item.getFlag3())); cell.setCellType(HSSFCell.CELL_TYPE_STRING); cell.setCellStyle(styleCenter); cell.setCellValue(colVal); } public String exec(){ final String EXTENSION = "xls"; HttpServletResponse res = (HttpServletResponse)FacesContext.getCurrentInstance().getExternalContext().getResponse(); HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.createSheet("Data"); HSSFCellStyle styleHeader = wb.createCellStyle(); HSSFFont fontHeader = wb.createFont(); fontHeader.setBoldweight((short) 2); fontHeader.setFontHeightInPoints((short) 14); fontHeader.setFontName("Arial"); styleHeader.setFont(fontHeader); HSSFFont font = wb.createFont(); font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); HSSFCellStyle cellStyle = wb.createCellStyle(); cellStyle.setFillPattern(HSSFCellStyle.FINE_DOTS); cellStyle.setFillBackgroundColor(new HSSFColor.GREY_25_PERCENT().getIndex()); HSSFRichTextString colVal = new HSSFRichTextString("deleteMe"); HSSFRow row = sheet.createRow((short)0); HSSFCell cell = row.createCell((short)0); cell.setCellStyle(styleHeader); cell.setCellValue(colVal); ////// Полезно HSSFCellStyle styleCenter = wb.createCellStyle(); styleCenter.setAlignment(HSSFCellStyle.ALIGN_CENTER); HSSFCellStyle styleRight = wb.createCellStyle(); styleRight.setAlignment(HSSFCellStyle.ALIGN_RIGHT); ///// if (FacesContext.getCurrentInstance().getViewRoot() == null) { this.localizedMessages_ind = ResourceBundle.getBundle( "ru.bpc.locale.cashmanagement.forecasting.currencyOut", Locale.getDefault()); this.localizedMessages_com = ResourceBundle.getBundle( "ru.bpc.locale.cashmanagement.common", Locale.getDefault()); } else { this.localizedMessages_ind = ResourceBundle.getBundle( "ru.bpc.locale.cashmanagement.forecasting.currencyOut", FacesContext.getCurrentInstance().getViewRoot().getLocale()); this.localizedMessages_com = ResourceBundle.getBundle( "ru.bpc.locale.cashmanagement.common", FacesContext.getCurrentInstance().getViewRoot().getLocale()); } sheet.autoSizeColumn((short)0); try{ String filename = getFilename("Currency_Exhaustion", EXTENSION); //List regions = LcCashManagement.getInstance().getAtmIncassationList(uid, filter); List dataList = getFilteredData(); res.setContentType("application/x-download"); res.setHeader("Content-Disposition", "attachment; filename=" + filename); if(dataList != null && dataList.size() != 0){ short i = 1; for (int k = 0 ; k < dataList.size(); k++){ AtmIncassationListItem current = (AtmIncassationListItem)dataList.get(k); insertInformAndHeader(current, sheet, font, cellStyle,row); row = sheet.createRow(i++); cell = row.createCell((short)0); colVal.applyFont(font); cell.setCellValue(colVal); cell.setCellStyle(cellStyle); insertData(row, sheet, current, styleCenter, styleRight); } } for (short k = 0; k < dataList.size(); k++ ){ sheet.autoSizeColumn(k); } try { wb.write(res.getOutputStream()); FacesContext.getCurrentInstance().responseComplete(); } catch (Exception e) { FacesContextUtils.addErrorExceptionMessage(e); _logger.error("",e); return null; } }catch(Exception e){ _logger.error("",e); FacesContextUtils.addErrorExceptionMessage(e); return null; } return "Back"; } } |
|||
|
||||
![]() ![]() ![]() |
Правила форума "Java" | |
|
Если Вам помогли, и атмосфера форума Вам понравилась, то заходите к нам чаще! С уважением, LSD, AntonSaburov, powerOn, tux. |
1 Пользователей читают эту тему (1 Гостей и 0 Скрытых Пользователей) | |
0 Пользователей: | |
« Предыдущая тема | Java EE (J2EE) и Spring | Следующая тема » |
|
По вопросам размещения рекламы пишите на vladimir(sobaka)vingrad.ru
Отказ от ответственности Powered by Invision Power Board(R) 1.3 © 2003 IPS, Inc. |