List of usage examples for org.apache.poi.ss.usermodel CellStyle setLocked
void setLocked(boolean locked);
From source file:com.globalsight.everest.webapp.pagehandler.administration.reports.generator.TranslationsEditReportGenerator.java
License:Apache License
/** * For Translations Edit Report, Write segment information into each row of * the sheet.//from w ww . j av a2 s .c o m * * @param p_sheet * the sheet * @param p_jobId * the job id * @param p_targetLang * the target locale String * @param p_srcPageId * the source page id * @param p_dateFormat * the data format * @param p_row * the segment row in sheet */ @SuppressWarnings({ "rawtypes", "unchecked" }) private int writeSegmentInfo(Workbook p_workBook, Sheet p_sheet, Job p_job, GlobalSightLocale p_targetLocale, String p_srcPageId, String p_dateFormat, int p_row) throws Exception { Vector<TargetPage> targetPages = new Vector<TargetPage>(); TranslationMemoryProfile tmp = null; Vector<String> excludItems = null; for (Workflow workflow : p_job.getWorkflows()) { if (cancel) return 0; if (Workflow.PENDING.equals(workflow.getState()) || Workflow.CANCELLED.equals(workflow.getState()) // || Workflow.EXPORT_FAILED.equals(workflow.getState()) || Workflow.IMPORT_FAILED.equals(workflow.getState())) { continue; } if (p_targetLocale.getId() == workflow.getTargetLocale().getId()) { targetPages = workflow.getTargetPages(); tmp = workflow.getJob().getL10nProfile().getTranslationMemoryProfile(); if (tmp != null) { excludItems = tmp.getJobExcludeTuTypes(); } } } if (targetPages.isEmpty()) { // If no corresponding target page exists, set the cell blank writeBlank(p_sheet, p_row, 11); } else { LeverageMatchLingManager lmLingManager = LingServerProxy.getLeverageMatchLingManager(); TermLeverageManager termLeverageManager = ServerProxy.getTermLeverageManager(); Locale sourcePageLocale = p_job.getSourceLocale().getLocale(); Locale targetPageLocale = p_targetLocale.getLocale(); TermLeverageOptions termLeverageOptions = getTermLeverageOptions(sourcePageLocale, targetPageLocale, p_job.getL10nProfile().getProject().getTermbaseName(), String.valueOf(p_job.getCompanyId())); Map<Long, Set<TermLeverageMatch>> termLeverageMatchResultMap = null; if (termLeverageOptions != null) { termLeverageMatchResultMap = termLeverageManager.getTermMatchesForPages(p_job.getSourcePages(), p_targetLocale); } String category = null; PseudoData pData = new PseudoData(); pData.setMode(PseudoConstants.PSEUDO_COMPACT); String sid = null; Set<Integer> rowsWithCommentSet = new HashSet<Integer>(); for (int i = 0; i < targetPages.size(); i++) { if (cancel) return 0; TargetPage targetPage = (TargetPage) targetPages.get(i); SourcePage sourcePage = targetPage.getSourcePage(); if (!"".equals(p_srcPageId) && !p_srcPageId.equals(String.valueOf(sourcePage.getId()))) { // ignore the source pages not equal to the one // if the request comes from pop up editor continue; } SegmentTuUtil.getTusBySourcePageId(sourcePage.getId()); List sourceTuvs = SegmentTuvUtil.getSourceTuvs(sourcePage); List targetTuvs = SegmentTuvUtil.getTargetTuvs(targetPage); MatchTypeStatistics tuvMatchTypes = lmLingManager.getMatchTypesForStatistics( sourcePage.getIdAsLong(), targetPage.getLocaleId(), p_job.getLeverageMatchThreshold()); Map<Long, Set<LeverageMatch>> fuzzyLeverageMatchMap = lmLingManager .getFuzzyMatches(sourcePage.getIdAsLong(), new Long(targetPage.getLocaleId())); sourcePageLocale = sourcePage.getGlobalSightLocale().getLocale(); targetPageLocale = targetPage.getGlobalSightLocale().getLocale(); boolean m_rtlSourceLocale = EditUtil.isRTLLocale(sourcePageLocale.toString()); boolean m_rtlTargetLocale = EditUtil.isRTLLocale(targetPageLocale.toString()); // Find segment all comments belong to this target page Map<Long, IssueImpl> issuesMap = CommentHelper.getIssuesMap(targetPage.getId()); for (int j = 0; j < targetTuvs.size(); j++) { if (cancel) return 0; int col = 0; Tuv targetTuv = (Tuv) targetTuvs.get(j); Tuv sourceTuv = (Tuv) sourceTuvs.get(j); category = sourceTuv.getTu(p_job.getId()).getTuType(); if (excludItems != null && excludItems.contains(category)) { continue; } // Comment List issueHistories = null; String lastComment = ""; String failure = ""; String commentStatus = ""; Issue issue = issuesMap.get(targetTuv.getId()); if (issue != null) { issueHistories = issue.getHistory(); failure = issue.getCategory(); commentStatus = issue.getStatus(); } if (issueHistories != null && issueHistories.size() > 0) { IssueHistory issueHistory = (IssueHistory) issueHistories.get(0); lastComment = issueHistory.getComment(); } sid = sourceTuv.getSid(); StringBuilder matches = getMatches(fuzzyLeverageMatchMap, tuvMatchTypes, excludItems, sourceTuvs, targetTuvs, sourceTuv, targetTuv, p_job.getId()); // Get Terminology/Glossary Source and Target. String sourceTerms = ""; String targetTerms = ""; if (termLeverageMatchResultMap != null && termLeverageMatchResultMap.size() > 0) { Set<TermLeverageMatch> termLeverageMatchSet = termLeverageMatchResultMap .get(sourceTuv.getId()); if (termLeverageMatchSet != null && termLeverageMatchSet.size() > 0) { TermLeverageMatch tlm = termLeverageMatchSet.iterator().next(); sourceTerms = tlm.getMatchedSourceTerm(); targetTerms = tlm.getMatchedTargetTerm(); } } Row currentRow = getRow(p_sheet, p_row); // Source segment with compact tags CellStyle srcStyle = m_rtlSourceLocale ? getRtlContentStyle(p_workBook) : getContentStyle(p_workBook); Cell cell_A = getCell(currentRow, col); cell_A.setCellValue(getSegment(pData, sourceTuv, m_rtlSourceLocale, p_job.getId())); cell_A.setCellStyle(srcStyle); col++; // Target segment with compact tags CellStyle trgStyle = m_rtlTargetLocale ? getRtlContentStyle(p_workBook) : getContentStyle(p_workBook); Cell cell_B = getCell(currentRow, col); cell_B.setCellValue(getSegment(pData, targetTuv, m_rtlTargetLocale, p_job.getId())); cell_B.setCellStyle(trgStyle); col++; // Modify the translation CellStyle modifyTranslationStyle = m_rtlTargetLocale ? getUnlockedRightStyle(p_workBook) : getUnlockedStyle(p_workBook); Cell cell_C = getCell(currentRow, col); cell_C.setCellValue(""); cell_C.setCellStyle(modifyTranslationStyle); col++; //Reviewers Comments Cell cell_D = getCell(currentRow, col); cell_D.setCellValue(lastComment); cell_D.setCellStyle(getContentStyle(p_workBook)); col++; // Translators Comments Cell cell_E = getCell(currentRow, col); cell_E.setCellValue(""); cell_E.setCellStyle(getUnlockedStyle(p_workBook)); col++; // Category failure Cell cell_F = getCell(currentRow, col); cell_F.setCellValue(failure); cell_F.setCellStyle(getContentStyle(p_workBook)); col++; // Comment Status Cell cell_G = getCell(currentRow, col); cell_G.setCellValue(commentStatus); CellStyle commentCS = p_workBook.createCellStyle(); commentCS.cloneStyleFrom(getContentStyle(p_workBook)); commentCS.setLocked(false); cell_G.setCellStyle(commentCS); // add comment status drop down list for current row. String[] statusArray = getCommentStatusList(lastComment); if (statusArray.length > 1) { rowsWithCommentSet.add(p_row); } col++; // TM match Cell cell_H = getCell(currentRow, col); cell_H.setCellValue(matches.toString()); cell_H.setCellStyle(getContentStyle(p_workBook)); col++; // Glossary source Cell cell_I = getCell(currentRow, col); cell_I.setCellValue(sourceTerms); cell_I.setCellStyle(getContentStyle(p_workBook)); col++; // Glossary target Cell cell_J = getCell(currentRow, col); cell_J.setCellValue(targetTerms); cell_J.setCellStyle(getContentStyle(p_workBook)); col++; // Job Id Cell cell_K = getCell(currentRow, col); cell_K.setCellValue(p_job.getId()); cell_K.setCellStyle(getContentStyle(p_workBook)); col++; // Segment id Cell cell_L = getCell(currentRow, col); cell_L.setCellValue(sourceTuv.getTu(p_job.getId()).getId()); cell_L.setCellStyle(getContentStyle(p_workBook)); col++; // Fix for GBS-1484 String externalPageId = sourcePage.getExternalPageId(); String[] pathNames = externalPageId.split("\\\\"); String name = pathNames[pathNames.length - 1]; boolean temp = pathNames[0].contains(")"); if (temp) { String[] firstNames = pathNames[0].split("\\)"); String detailName = firstNames[0]; name = name + detailName + ")"; } //Page Name Cell cell_M = getCell(currentRow, col); cell_M.setCellValue(name); cell_M.setCellStyle(getContentStyle(p_workBook)); col++; // SID Cell cell_N = getCell(currentRow, col); cell_N.setCellValue(sid); cell_N.setCellStyle(getContentStyle(p_workBook)); col++; p_row++; } } //Add comment status addCommentStatus(p_sheet, rowsWithCommentSet, p_row); // Add category failure drop down list here. addCategoryFailureValidation(p_sheet, SEGMENT_START_ROW, p_row - 1, CATEGORY_FAILURE_COLUMN, CATEGORY_FAILURE_COLUMN); } return p_row; }
From source file:com.globalsight.everest.webapp.pagehandler.administration.reports.generator.TranslationVerificationReportGenerator.java
License:Apache License
/** * For Translations Edit Report, Write segment information into each row of * the sheet.// w ww . j av a 2 s . c o m * * @param p_sheet * the sheet * @param p_jobId * the job id * @param p_targetLang * the target locale String * @param p_srcPageId * the source page id * @param p_dateFormat * the data format * @param p_row * the segment row in sheet */ @SuppressWarnings({ "rawtypes", "unchecked" }) private int writeSegmentInfo(Workbook p_workBook, Sheet p_sheet, Job p_job, GlobalSightLocale p_targetLocale, String p_srcPageId, String p_dateFormat, int p_row) throws Exception { Vector<TargetPage> targetPages = new Vector<TargetPage>(); TranslationMemoryProfile tmp = null; Vector<String> excludItems = null; for (Workflow workflow : p_job.getWorkflows()) { if (cancel) return 0; if (Workflow.PENDING.equals(workflow.getState()) || Workflow.CANCELLED.equals(workflow.getState()) // || Workflow.EXPORT_FAILED.equals(workflow.getState()) || Workflow.IMPORT_FAILED.equals(workflow.getState())) { continue; } if (p_targetLocale.getId() == workflow.getTargetLocale().getId()) { targetPages = workflow.getTargetPages(); tmp = workflow.getJob().getL10nProfile().getTranslationMemoryProfile(); if (tmp != null) { excludItems = tmp.getJobExcludeTuTypes(); } } } if (targetPages.isEmpty()) { // If no corresponding target page exists, set the cell blank writeBlank(p_sheet, p_row, 11); } else { LeverageMatchLingManager lmLingManager = LingServerProxy.getLeverageMatchLingManager(); TermLeverageManager termLeverageManager = ServerProxy.getTermLeverageManager(); Locale sourcePageLocale = p_job.getSourceLocale().getLocale(); Locale targetPageLocale = p_targetLocale.getLocale(); TermLeverageOptions termLeverageOptions = getTermLeverageOptions(sourcePageLocale, targetPageLocale, p_job.getL10nProfile().getProject().getTermbaseName(), String.valueOf(p_job.getCompanyId())); Map<Long, Set<TermLeverageMatch>> termLeverageMatchResultMap = null; if (termLeverageOptions != null) { termLeverageMatchResultMap = termLeverageManager.getTermMatchesForPages(p_job.getSourcePages(), p_targetLocale); } String category = null; PseudoData pData = new PseudoData(); pData.setMode(PseudoConstants.PSEUDO_COMPACT); String sid = null; Set<Integer> rowsWithCommentSet = new HashSet<Integer>(); for (int i = 0; i < targetPages.size(); i++) { if (cancel) return 0; TargetPage targetPage = (TargetPage) targetPages.get(i); SourcePage sourcePage = targetPage.getSourcePage(); if (!"".equals(p_srcPageId) && !p_srcPageId.equals(String.valueOf(sourcePage.getId()))) { // ignore the source pages not equal to the one // if the request comes from pop up editor continue; } SegmentTuUtil.getTusBySourcePageId(sourcePage.getId()); List sourceTuvs = SegmentTuvUtil.getSourceTuvs(sourcePage); List targetTuvs = SegmentTuvUtil.getTargetTuvs(targetPage); MatchTypeStatistics tuvMatchTypes = lmLingManager.getMatchTypesForStatistics( sourcePage.getIdAsLong(), targetPage.getLocaleId(), p_job.getLeverageMatchThreshold()); Map<Long, Set<LeverageMatch>> fuzzyLeverageMatchMap = lmLingManager .getFuzzyMatches(sourcePage.getIdAsLong(), new Long(targetPage.getLocaleId())); Map<Long, Tuv> allTuvMap = this.getAllTuvsMap(targetPage); sourcePageLocale = sourcePage.getGlobalSightLocale().getLocale(); targetPageLocale = targetPage.getGlobalSightLocale().getLocale(); boolean m_rtlSourceLocale = EditUtil.isRTLLocale(sourcePageLocale.toString()); boolean m_rtlTargetLocale = EditUtil.isRTLLocale(targetPageLocale.toString()); // Find segment all comments belong to this target page Map<Long, IssueImpl> issuesMap = CommentHelper.getIssuesMap(targetPage.getId()); for (int j = 0; j < targetTuvs.size(); j++) { if (cancel) return 0; int col = 0; Tuv targetTuv = (Tuv) targetTuvs.get(j); Tuv sourceTuv = (Tuv) sourceTuvs.get(j); category = sourceTuv.getTu(p_job.getId()).getTuType(); if (excludItems != null && excludItems.contains(category)) { continue; } // Comment List issueHistories = null; String lastComment = ""; String failure = ""; String commentStatus = ""; Issue issue = issuesMap.get(targetTuv.getId()); if (issue != null) { issueHistories = issue.getHistory(); failure = issue.getCategory(); commentStatus = issue.getStatus(); } if (issueHistories != null && issueHistories.size() > 0) { IssueHistory issueHistory = (IssueHistory) issueHistories.get(0); lastComment = issueHistory.getComment(); } sid = sourceTuv.getSid(); StringBuilder matches = getMatches(fuzzyLeverageMatchMap, tuvMatchTypes, excludItems, sourceTuvs, targetTuvs, sourceTuv, targetTuv, p_job.getId()); // Get Terminology/Glossary Source and Target. String sourceTerms = ""; String targetTerms = ""; if (termLeverageMatchResultMap != null && termLeverageMatchResultMap.size() > 0) { Set<TermLeverageMatch> termLeverageMatchSet = termLeverageMatchResultMap .get(sourceTuv.getId()); if (termLeverageMatchSet != null && termLeverageMatchSet.size() > 0) { TermLeverageMatch tlm = termLeverageMatchSet.iterator().next(); sourceTerms = tlm.getMatchedSourceTerm(); targetTerms = tlm.getMatchedTargetTerm(); } } Row currentRow = getRow(p_sheet, p_row); // Source segment with compact tags CellStyle srcStyle = m_rtlSourceLocale ? getRtlContentStyle(p_workBook) : getContentStyle(p_workBook); Cell cell_A = getCell(currentRow, col); cell_A.setCellValue(getSegment(pData, sourceTuv, m_rtlSourceLocale, p_job.getId())); cell_A.setCellStyle(srcStyle); col++; // the translation after the translation activity CellStyle trgStyle = null; String previousSegments = getPreviousSegments(allTuvMap, targetTuv.getId(), targetTuv, p_job.getId(), pData); String currentSegments = getSegment(pData, targetTuv, m_rtlTargetLocale, p_job.getId()); Cell cell_B = getCell(currentRow, col); cell_B.setCellValue(previousSegments); if (StringUtil.isNotEmpty(previousSegments) && !previousSegments.endsWith(currentSegments)) { trgStyle = m_rtlTargetLocale ? getRtlContentStyle1(p_workBook) : getContentStyle1(p_workBook); } else { trgStyle = m_rtlTargetLocale ? getRtlContentStyle(p_workBook) : getContentStyle(p_workBook); } cell_B.setCellStyle(trgStyle); col++; // the translation after the review activity // CellStyle trgStyle = m_rtlTargetLocale ? // getRtlContentStyle(p_workBook) // : getContentStyle(p_workBook); Cell cell_C = getCell(currentRow, col); cell_C.setCellValue(currentSegments); cell_C.setCellStyle(trgStyle); col++; // Modify the translation CellStyle modifyTranslationStyle = m_rtlTargetLocale ? getUnlockedRightStyle(p_workBook) : getUnlockedStyle(p_workBook); Cell cell_D = getCell(currentRow, col); cell_D.setCellValue(""); cell_D.setCellStyle(modifyTranslationStyle); col++; // Reviewers Comments Cell cell_E = getCell(currentRow, col); cell_E.setCellValue(lastComment); cell_E.setCellStyle(getContentStyle(p_workBook)); col++; // Translators Comments Cell cell_F = getCell(currentRow, col); cell_F.setCellValue(""); cell_F.setCellStyle(getUnlockedStyle(p_workBook)); col++; // Category failure Cell cell_G = getCell(currentRow, col); cell_G.setCellValue(failure); cell_G.setCellStyle(getContentStyle(p_workBook)); col++; // Comment Status Cell cell_H = getCell(currentRow, col); cell_H.setCellValue(commentStatus); CellStyle commentCS = p_workBook.createCellStyle(); commentCS.cloneStyleFrom(getContentStyle(p_workBook)); commentCS.setLocked(false); cell_H.setCellStyle(commentCS); // add comment status drop down list for current row. String[] statusArray = getCommentStatusList(lastComment); if (statusArray.length > 1) { rowsWithCommentSet.add(p_row); } col++; // TM match Cell cell_I = getCell(currentRow, col); cell_I.setCellValue(matches.toString()); cell_I.setCellStyle(getContentStyle(p_workBook)); col++; // Glossary source Cell cell_J = getCell(currentRow, col); cell_J.setCellValue(sourceTerms); cell_J.setCellStyle(getContentStyle(p_workBook)); col++; // Glossary target Cell cell_K = getCell(currentRow, col); cell_K.setCellValue(targetTerms); cell_K.setCellStyle(getContentStyle(p_workBook)); col++; // Job Id Cell cell_L = getCell(currentRow, col); cell_L.setCellValue(p_job.getId()); cell_L.setCellStyle(getContentStyle(p_workBook)); col++; // Segment id Cell cell_M = getCell(currentRow, col); cell_M.setCellValue(sourceTuv.getTu(p_job.getId()).getId()); cell_M.setCellStyle(getContentStyle(p_workBook)); col++; // Fix for GBS-1484 String externalPageId = sourcePage.getExternalPageId(); String[] pathNames = externalPageId.split("\\\\"); String name = pathNames[pathNames.length - 1]; boolean temp = pathNames[0].contains(")"); if (temp) { String[] firstNames = pathNames[0].split("\\)"); String detailName = firstNames[0]; name = name + detailName + ")"; } // Page Name Cell cell_N = getCell(currentRow, col); cell_N.setCellValue(name); cell_N.setCellStyle(getContentStyle(p_workBook)); col++; // SID Cell cell_O = getCell(currentRow, col); cell_O.setCellValue(sid); cell_O.setCellStyle(getContentStyle(p_workBook)); col++; p_row++; } } // Add comment status addCommentStatus(p_sheet, rowsWithCommentSet, p_row); // Add category failure drop down list here. addCategoryFailureValidation(p_sheet, SEGMENT_START_ROW, p_row - 1, CATEGORY_FAILURE_COLUMN, CATEGORY_FAILURE_COLUMN); } return p_row; }
From source file:com.ncc.excel.test.ExcelUtil.java
License:Apache License
/** * ????? /*from w w w. ja va 2s . com*/ * * @param fromStyle * @param toStyle */ public static void copyCellStyle(CellStyle fromStyle, CellStyle toStyle) { toStyle.setAlignment(fromStyle.getAlignment()); // toStyle.setBorderBottom(fromStyle.getBorderBottom()); toStyle.setBorderLeft(fromStyle.getBorderLeft()); toStyle.setBorderRight(fromStyle.getBorderRight()); toStyle.setBorderTop(fromStyle.getBorderTop()); toStyle.setTopBorderColor(fromStyle.getTopBorderColor()); toStyle.setBottomBorderColor(fromStyle.getBottomBorderColor()); toStyle.setRightBorderColor(fromStyle.getRightBorderColor()); toStyle.setLeftBorderColor(fromStyle.getLeftBorderColor()); // ? toStyle.setFillBackgroundColor(fromStyle.getFillBackgroundColor()); toStyle.setFillForegroundColor(fromStyle.getFillForegroundColor()); // ?? toStyle.setDataFormat(fromStyle.getDataFormat()); toStyle.setFillPattern(fromStyle.getFillPattern()); // toStyle.setFont(fromStyle.getFont(null)); toStyle.setHidden(fromStyle.getHidden()); toStyle.setIndention(fromStyle.getIndention());// toStyle.setLocked(fromStyle.getLocked()); toStyle.setRotation(fromStyle.getRotation());// toStyle.setVerticalAlignment(fromStyle.getVerticalAlignment()); toStyle.setWrapText(fromStyle.getWrapText()); }
From source file:Compras.generaCotizacion.java
void exel() { h = new Herramientas(this.user, 0); h.session(sessionPrograma);// w ww . j av a 2 s.c om javax.swing.JFileChooser jF1 = new javax.swing.JFileChooser(); jF1.setFileFilter(new ExtensionFileFilter("Excel document (*.xls)", new String[] { "xls" })); String ruta = null; if (jF1.showSaveDialog(null) == jF1.APPROVE_OPTION) { ruta = jF1.getSelectedFile().getAbsolutePath(); if (ruta != null) { if (ruta.endsWith(".xls") == true) archivoXLS = new File(ruta); else archivoXLS = new File(ruta + ".xls"); try { if (archivoXLS.exists()) archivoXLS.delete(); archivoXLS.createNewFile(); Workbook libro = new HSSFWorkbook(); FileOutputStream archivo = new FileOutputStream(archivoXLS); Sheet hoja = libro.createSheet("Cotizacion"); Font font = libro.createFont(); font.setFontHeightInPoints((short) 24); font.setFontName("Arial"); font.setItalic(false); font.setBold(true); Font font10 = libro.createFont(); font10.setFontHeightInPoints((short) 10); font10.setFontName("Arial"); font10.setItalic(false); font10.setBold(false); font10.setColor(new HSSFColor.YELLOW().getIndex()); Font font11 = libro.createFont(); font11.setFontHeightInPoints((short) 10); font11.setFontName("Arial"); font10.setItalic(false); font10.setBold(false); font11.setColor(new HSSFColor.BLACK().getIndex()); // Fonts are set into a style so create a new one to use. CellStyle style = libro.createCellStyle(); CellStyle desBloqueo = libro.createCellStyle(); CellStyle desBloqueo1 = libro.createCellStyle(); CellStyle desBloqueoFecha = libro.createCellStyle(); style.setFont(font); desBloqueo.setFont(font10); desBloqueo.setLocked(false); desBloqueo.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); desBloqueo.setFillBackgroundColor(new HSSFColor.GREEN().getIndex()); desBloqueo1.setFont(font11); desBloqueo1.setLocked(false); desBloqueo1.setFillBackgroundColor(new HSSFColor.WHITE().getIndex()); desBloqueoFecha.setFont(font10); desBloqueoFecha.setLocked(false); desBloqueoFecha.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); desBloqueoFecha.setFillBackgroundColor(new HSSFColor.GREEN().getIndex()); desBloqueoFecha.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy")); Session session = HibernateUtil.getSessionFactory().openSession(); session.beginTransaction().begin(); Orden ord = (Orden) session.get(Orden.class, Integer.parseInt(orden)); Configuracion con = (Configuracion) session.get(Configuracion.class, 1); hoja.setColumnWidth(5, 15000); Row r0 = hoja.createRow(0); Cell celdaTitulo = r0.createCell(0); celdaTitulo.setCellValue(con.getEmpresa()); celdaTitulo.setCellStyle(style); Row r1 = hoja.createRow(1); r1.createCell(6).setCellValue("Orden de Taller:"); r1.createCell(7).setCellValue(orden); Row r2 = hoja.createRow(2); r2.createCell(0).setCellValue("Marca:"); r2.createCell(1).setCellValue(ord.getMarca().getMarcaNombre()); r2.createCell(6).setCellValue("N Serie:"); r2.createCell(7).setCellValue(ord.getNoSerie()); Row r3 = hoja.createRow(3); r3.createCell(0).setCellValue("Tipo:"); r3.createCell(1).setCellValue(ord.getTipo().getTipoNombre()); r3.createCell(6).setCellValue("N Motor:"); r3.createCell(7).setCellValue(ord.getNoMotor()); Row r4 = hoja.createRow(4); r4.createCell(0).setCellValue("NP:"); r4.createCell(1).setCellValue(t_datos1.getValueAt(t_datos1.getSelectedRow(), 1).toString()); r4.createCell(2).setCellValue("Proveedor:"); r4.createCell(3).setCellValue(t_datos1.getValueAt(t_datos1.getSelectedRow(), 2).toString()); r4.createCell(6).setCellValue("Modelo:"); r4.createCell(7).setCellValue("" + ord.getModelo()); Row r5 = hoja.createRow(5); r5.createCell(0).setCellValue( "**********************************************************************************[Nota: Solo puedes editar las celdas de color]*******************************************************************************"); Row r6 = hoja.createRow(6); r6.createCell(0).setCellValue("Partida"); r6.createCell(1).setCellValue("sub"); r6.createCell(2).setCellValue("Cantidad"); r6.createCell(3).setCellValue("U/Medida"); r6.createCell(4).setCellValue("N Parte"); r6.createCell(5).setCellValue("Descripcion"); r6.createCell(6).setCellValue("Instruccin"); r6.createCell(7).setCellValue("Precio c/u"); r6.createCell(8).setCellValue("T o t a l"); r6.createCell(9).setCellValue("Origen"); r6.createCell(10).setCellValue("Pazo"); Row r7 = hoja.createRow(7); r7.createCell(0).setCellValue( "**********************************************************************************************************************************************************************************************************************"); List misCotizaciones = null; Query query = session.createQuery("SELECT DISTINCT par FROM Partida par " + "RIGHT JOIN FETCH par.partidaCotizacions partC " + "RIGHT JOIN partC.cotizacion cot " + "where cot.idCotizacion=" + t_datos1.getValueAt(t_datos1.getSelectedRow(), 0).toString() + " order by par.idEvaluacion asc, par.subPartida asc"); //misCotizaciones=c.addOrder(Order.asc("idCotizacion")).list(); misCotizaciones = query.list(); if (misCotizaciones.size() > 0) { for (int i = 0; i < misCotizaciones.size(); i++) { Partida Part = (Partida) misCotizaciones.get(i); Row fila = hoja.createRow(i + 8); fila.createCell(0).setCellValue(Part.getIdEvaluacion()); fila.createCell(1).setCellValue(Part.getSubPartida()); fila.createCell(2).setCellValue(Part.getCant()); fila.createCell(3).setCellValue(Part.getMed()); Cell aux = fila.createCell(4); aux.setCellStyle(desBloqueo); if (Part.getEjemplar() != null) aux.setCellValue(Part.getEjemplar().getIdParte()); else aux.setCellValue(""); fila.createCell(5).setCellValue(Part.getCatalogo().getNombre()); int fil = i + 9; Cell a10 = fila.createCell(6); a10.setCellStyle(desBloqueo1); a10.setCellValue(Part.getInstruccion()); Cell a6 = fila.createCell(7); a6.setCellStyle(desBloqueo); a6.setCellValue(""); Cell celForm = fila.createCell(8); celForm.setCellType(HSSFCell.CELL_TYPE_FORMULA); celForm.setCellFormula("H" + fil + "*C" + fil); if (Part.isOri() == true) fila.createCell(9).setCellValue("Ori"); else if (Part.isNal() == true) fila.createCell(9).setCellValue("Nal"); else if (Part.isDesm() == true) fila.createCell(9).setCellValue("Des"); else fila.createCell(9).setCellValue(""); Cell a9 = fila.createCell(10); a9.setCellValue(""); a9.setCellStyle(desBloqueo); } } hoja.protectSheet("04650077"); libro.write(archivo); archivo.close(); Desktop.getDesktop().open(archivoXLS); if (session != null) if (session.isOpen()) session.close(); } catch (Exception e) { System.out.println(e); e.printStackTrace(); JOptionPane.showMessageDialog(this, "No se pudo realizar el reporte si el archivo esta abierto"); } } } }
From source file:org.alanwilliamson.openbd.plugin.spreadsheet.SpreadSheetFormatOptions.java
License:Open Source License
public static CellStyle createCellStyle(Workbook workbook, cfStructData _struct) throws Exception { CellStyle style = workbook.createCellStyle(); if (_struct.containsKey("alignment")) { String v = _struct.getData("alignment").getString(); Short s = lookup_alignment.get(v); if (s == null) { throw new Exception("invalid parameter for 'alignment' (" + v + ")"); } else/* w ww . j a va 2 s. co m*/ style.setAlignment(s); } if (_struct.containsKey("bottomborder")) { String v = _struct.getData("bottomborder").getString(); Short s = lookup_border.get(v); if (s == null) { throw new Exception("invalid parameter for 'bottomborder' (" + v + ")"); } else style.setBorderBottom(s); } if (_struct.containsKey("topborder")) { String v = _struct.getData("topborder").getString(); Short s = lookup_border.get(v); if (s == null) { throw new Exception("invalid parameter for 'topborder' (" + v + ")"); } else style.setBorderTop(s); } if (_struct.containsKey("leftborder")) { String v = _struct.getData("leftborder").getString(); Short s = lookup_border.get(v); if (s == null) { throw new Exception("invalid parameter for 'leftborder' (" + v + ")"); } else style.setBorderLeft(s); } if (_struct.containsKey("rightborder")) { String v = _struct.getData("rightborder").getString(); Short s = lookup_border.get(v); if (s == null) { throw new Exception("invalid parameter for 'rightborder' (" + v + ")"); } else style.setBorderRight(s); } if (_struct.containsKey("bottombordercolor")) { String v = _struct.getData("bottombordercolor").getString(); Short s = lookup_colors.get(v); if (s == null) { throw new Exception("invalid parameter for 'bottombordercolor' (" + v + ")"); } else style.setBottomBorderColor(s); } if (_struct.containsKey("topbordercolor")) { String v = _struct.getData("topbordercolor").getString(); Short s = lookup_colors.get(v); if (s == null) { throw new Exception("invalid parameter for 'topbordercolor' (" + v + ")"); } else style.setTopBorderColor(s); } if (_struct.containsKey("leftbordercolor")) { String v = _struct.getData("leftbordercolor").getString(); Short s = lookup_colors.get(v); if (s == null) { throw new Exception("invalid parameter for 'leftbordercolor' (" + v + ")"); } else style.setLeftBorderColor(s); } if (_struct.containsKey("rightbordercolor")) { String v = _struct.getData("rightbordercolor").getString(); Short s = lookup_colors.get(v); if (s == null) { throw new Exception("invalid parameter for 'rightbordercolor' (" + v + ")"); } else style.setRightBorderColor(s); } if (_struct.containsKey("fillpattern")) { String v = _struct.getData("fillpattern").getString(); Short s = lookup_fillpatten.get(v); if (s == null) { throw new Exception("invalid parameter for 'fillpattern' (" + v + ")"); } else style.setFillPattern(s); } if (_struct.containsKey("fgcolor")) { String v = _struct.getData("fgcolor").getString(); Short s = lookup_colors.get(v); if (s == null) { throw new Exception("invalid parameter for 'fgcolor' (" + v + ")"); } else style.setFillForegroundColor(s); } if (_struct.containsKey("bgcolor")) { String v = _struct.getData("bgcolor").getString(); Short s = lookup_colors.get(v); if (s == null) { throw new Exception("invalid parameter for 'bgcolor' (" + v + ")"); } else style.setFillBackgroundColor(s); } if (_struct.containsKey("textwrap")) { Boolean b = _struct.getData("textwrap").getBoolean(); style.setWrapText(b); } if (_struct.containsKey("hidden")) { Boolean b = _struct.getData("hidden").getBoolean(); style.setHidden(b); } if (_struct.containsKey("locked")) { Boolean b = _struct.getData("locked").getBoolean(); style.setLocked(b); } if (_struct.containsKey("indent")) { style.setIndention((short) _struct.getData("indent").getInt()); } if (_struct.containsKey("rotation")) { style.setRotation((short) _struct.getData("rotation").getInt()); } if (_struct.containsKey("dateformat")) { style.setDataFormat(workbook.createDataFormat().getFormat(_struct.getData("dateformat").getString())); } // Manage the fonts Font f = workbook.createFont(); if (_struct.containsKey("strikeout")) { f.setStrikeout(true); } if (_struct.containsKey("bold")) { Boolean b = _struct.getData("bold").getBoolean(); f.setBoldweight(b ? Font.BOLDWEIGHT_BOLD : Font.BOLDWEIGHT_NORMAL); } if (_struct.containsKey("underline")) { String v = _struct.getData("underline").getString(); Byte b = lookup_underline.get(v); if (b == null) { throw new Exception("invalid parameter for 'underline' (" + v + ")"); } else f.setUnderline(b); } if (_struct.containsKey("color")) { String v = _struct.getData("color").getString(); Short s = lookup_colors.get(v); if (s == null) { throw new Exception("invalid parameter for 'color' (" + v + ")"); } else f.setColor(s); } if (_struct.containsKey("fontsize")) { int s = _struct.getData("fontsize").getInt(); f.setFontHeightInPoints((short) s); } if (_struct.containsKey("font")) { f.setFontName(_struct.getData("font").getString()); } style.setFont(f); return style; }
From source file:org.eclipse.emfforms.internal.spreadsheet.core.transfer.EMFFormsSpreadsheetExporterImpl.java
License:Open Source License
private void addDefaultCellStyles(Workbook workbook, Map<String, CellStyle> keyStyleMap) { final CellStyle cellStyle = workbook.createCellStyle(); cellStyle.setLocked(true); keyStyleMap.put(EMFFormsCellStyleConstants.LOCKED, cellStyle); final CellStyle cellStyle2 = workbook.createCellStyle(); cellStyle2.setLocked(true);//w w w .ja v a2 s. c o m cellStyle2.setWrapText(true); keyStyleMap.put(EMFFormsCellStyleConstants.LOCKED_AND_WRAPPED, cellStyle2); final CellStyle cellStyle3 = workbook.createCellStyle(); cellStyle3.setDataFormat((short) BuiltinFormats.getBuiltinFormat("text")); //$NON-NLS-1$ keyStyleMap.put(EMFFormsCellStyleConstants.TEXT, cellStyle3); final CellStyle cellStyle4 = workbook.createCellStyle(); cellStyle4.setDataFormat((short) BuiltinFormats.getBuiltinFormat("m/d/yy")); //$NON-NLS-1$ keyStyleMap.put(EMFFormsCellStyleConstants.DATE, cellStyle4); }
From source file:org.openelis.bean.WorksheetExcelHelperBean.java
License:Open Source License
private void createStyles(HSSFWorkbook wb) { CellStyle dateTimeEditStyle, dateTimeNoEditStyle, headerStyle, rowEditStyle, rowNoEditStyle; CreationHelper helper;/*from w w w . j a v a 2 s .com*/ Font font; helper = wb.getCreationHelper(); styles = new HashMap<String, CellStyle>(); font = wb.createFont(); font.setColor(IndexedColors.WHITE.getIndex()); headerStyle = wb.createCellStyle(); headerStyle.setAlignment(CellStyle.ALIGN_LEFT); headerStyle.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM); headerStyle.setFillPattern(CellStyle.SOLID_FOREGROUND); headerStyle.setFillForegroundColor(IndexedColors.GREY_80_PERCENT.getIndex()); headerStyle.setFont(font); headerStyle.setLocked(true); styles.put("header", headerStyle); rowEditStyle = wb.createCellStyle(); rowEditStyle.setAlignment(CellStyle.ALIGN_LEFT); rowEditStyle.setVerticalAlignment(CellStyle.VERTICAL_TOP); rowEditStyle.setLocked(false); styles.put("row_edit", rowEditStyle); rowNoEditStyle = wb.createCellStyle(); rowNoEditStyle.setAlignment(CellStyle.ALIGN_LEFT); rowNoEditStyle.setFillPattern(CellStyle.SOLID_FOREGROUND); rowNoEditStyle.setFillForegroundColor(IndexedColors.PALE_BLUE.getIndex()); rowNoEditStyle.setVerticalAlignment(CellStyle.VERTICAL_TOP); rowNoEditStyle.setLocked(true); styles.put("row_no_edit", rowNoEditStyle); dateTimeEditStyle = wb.createCellStyle(); dateTimeEditStyle.setDataFormat(helper.createDataFormat().getFormat("yyyy-MM-dd hh:mm")); dateTimeEditStyle.setAlignment(CellStyle.ALIGN_LEFT); dateTimeEditStyle.setVerticalAlignment(CellStyle.VERTICAL_TOP); dateTimeEditStyle.setLocked(false); styles.put("datetime_edit", dateTimeEditStyle); dateTimeNoEditStyle = wb.createCellStyle(); dateTimeNoEditStyle.setDataFormat(helper.createDataFormat().getFormat("yyyy-MM-dd hh:mm")); dateTimeNoEditStyle.setAlignment(CellStyle.ALIGN_LEFT); dateTimeNoEditStyle.setFillPattern(CellStyle.SOLID_FOREGROUND); dateTimeNoEditStyle.setFillForegroundColor(IndexedColors.PALE_BLUE.getIndex()); dateTimeNoEditStyle.setVerticalAlignment(CellStyle.VERTICAL_TOP); dateTimeNoEditStyle.setLocked(true); styles.put("datetime_no_edit", dateTimeNoEditStyle); }
From source file:output.ExcelM3Upgrad.java
/** * create a library of cell styles//from w ww. j a v a2 s . c om */ private static Map<String, CellStyle> createStyles(Workbook wb) { Map<String, CellStyle> styles = new HashMap<>(); DataFormat df = wb.createDataFormat(); Font font1 = wb.createFont(); CellStyle style; Font headerFont = wb.createFont(); headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD); style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_CENTER); style.setFillForegroundColor(IndexedColors.LIGHT_CORNFLOWER_BLUE.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setFont(headerFont); styles.put("header", style); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_CENTER); style.setFont(font1); style.setLocked(false); styles.put("cell_centered", style); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_CENTER); style.setFont(font1); style.setLocked(true); styles.put("cell_centered_locked", style); // style = createBorderedStyle(wb); // style.setAlignment(CellStyle.ALIGN_CENTER); // style.setFillForegroundColor(IndexedColors.LIGHT_CORNFLOWER_BLUE.getIndex()); // style.setFillPattern(CellStyle.SOLID_FOREGROUND); // style.setFont(headerFont); // style.setDataFormat(df.getFormat("d-mmm")); // styles.put("header_date", style); font1.setBoldweight(Font.BOLDWEIGHT_BOLD); style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_LEFT); style.setFont(font1); styles.put("cell_b", style); style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_CENTER); style.setFont(font1); style.setLocked(false); styles.put("cell_b_centered", style); style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_CENTER); style.setFont(font1); style.setLocked(true); styles.put("cell_b_centered_locked", style); style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_RIGHT); style.setFont(font1); style.setDataFormat(df.getFormat("d-mmm")); styles.put("cell_b_date", style); style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_RIGHT); style.setFont(font1); style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setDataFormat(df.getFormat("d-mmm")); styles.put("cell_g", style); Font font2 = wb.createFont(); font2.setColor(IndexedColors.BLUE.getIndex()); font2.setBoldweight(Font.BOLDWEIGHT_BOLD); style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_LEFT); style.setFont(font2); styles.put("cell_bb", style); style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_RIGHT); style.setFont(font1); style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setDataFormat(df.getFormat("d-mmm")); styles.put("cell_bg", style); Font font3 = wb.createFont(); font3.setFontHeightInPoints((short) 14); font3.setColor(IndexedColors.DARK_BLUE.getIndex()); font3.setBoldweight(Font.BOLDWEIGHT_BOLD); style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_LEFT); style.setFont(font3); style.setWrapText(true); styles.put("cell_h", style); style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_LEFT); style.setWrapText(true); styles.put("cell_normal", style); style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_CENTER); style.setWrapText(true); styles.put("cell_normal_centered", style); style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_RIGHT); style.setWrapText(true); style.setDataFormat(df.getFormat("d-mmm")); styles.put("cell_normal_date", style); style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_LEFT); style.setIndention((short) 1); style.setWrapText(true); styles.put("cell_indented", style); style = createBorderedStyle(wb); style.setFillForegroundColor(IndexedColors.BLUE.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); styles.put("cell_blue", style); return styles; }