package art.servers.gost.access.reports; import art.servers.ServerException; import art.servers.Shared; import art.servers.gost.access.configuration.Configuration; import com.sun.star.beans.PropertyValue; import com.sun.star.frame.XComponentLoader; import com.sun.star.frame.XDesktop; import com.sun.star.frame.XStorable; import com.sun.star.lang.XComponent; import com.sun.star.lang.XMultiComponentFactory; import com.sun.star.lib.uno.adapter.ByteArrayToXInputStreamAdapter; import com.sun.star.lib.uno.adapter.OutputStreamToXOutputStreamAdapter; import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.XComponentContext; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.PrintStream; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.TimeZone; import java.util.regex.Matcher; import java.util.regex.Pattern; import ooo.connector.BootstrapSocketConnector; import org.apache.poi.ss.usermodel.BorderStyle; import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.usermodel.DataFormatter; import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.ss.util.CellReference; import org.apache.poi.ss.util.RegionUtil; import org.apache.poi.xssf.streaming.SXSSFCell; import org.apache.poi.xssf.streaming.SXSSFRow; import org.apache.poi.xssf.streaming.SXSSFSheet; import org.apache.poi.xssf.streaming.SXSSFWorkbook; import org.apache.poi.xssf.usermodel.XSSFCell; import org.apache.poi.xssf.usermodel.XSSFFormulaEvaluator; import org.apache.poi.xssf.usermodel.XSSFRow; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; public class XLSX { protected XSSFWorkbook workbook; protected String language = null; public XLSX () { } public XLSX (File source) throws Exception { workbook = new XSSFWorkbook(new FileInputStream(source)); } public byte[] save(String format) throws Exception { if ((format.equalsIgnoreCase("xlsx")) || (format.equalsIgnoreCase("xlsm"))) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); workbook.write(bos); byte[] xlsx = bos.toByteArray(); bos.close(); return xlsx; } if (format.equalsIgnoreCase("pdf")) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); workbook.write(bos); byte[] xlsx = bos.toByteArray(); bos.close(); return toPDF(xlsx); } if (format.equalsIgnoreCase("csv")) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); workbook.write(bos); byte[] xlsx = bos.toByteArray(); bos.close(); return toSCV(xlsx); } throw new Exception("Unknow format"); } public byte[] saveAndClose(String format) throws Exception { byte[] result = save(format); close(); return result; } public void close () { try { workbook.close(); } catch (Exception e) { } } public byte[] save(SXSSFWorkbook sxworkbook, String format) throws Exception { if ((format.equalsIgnoreCase("xlsx")) || (format.equalsIgnoreCase("xlsm"))) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); sxworkbook.write(bos); byte[] xlsx = bos.toByteArray(); bos.close(); return xlsx; } if (format.equalsIgnoreCase("pdf")) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); sxworkbook.write(bos); byte[] xlsx = bos.toByteArray(); bos.close(); return toPDF(xlsx); } if (format.equalsIgnoreCase("csv")) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); sxworkbook.write(bos); byte[] xlsx = bos.toByteArray(); bos.close(); return toSCV(xlsx); } throw new Exception("Unknow format"); } public byte[] saveAndClose(SXSSFWorkbook sxworkbook, String format) throws Exception { byte[] result = save(sxworkbook, format); close(sxworkbook); return result; } public void close (SXSSFWorkbook sxworkbook) { close(); try { sxworkbook.close(); } catch (Exception e) { } } public XSSFCell getXSSFCell(XSSFSheet xssfsheet, String reference) { CellReference cellReference = new CellReference(reference); XSSFRow row = xssfsheet.getRow(cellReference.getRow()); XSSFCell cell = row.getCell(cellReference.getCol()); return cell; } // La primera columna e 1 y no 0 private char[] chars = new char[] {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'}; protected String columnName (int index) { index -= 1; int quotient = index / 26; if (quotient > 0) { return columnName(quotient) + chars[index % 26]; } else { return "" + chars[index % 26]; } } public void createRow (XSSFSheet hoja, int numeroFilaReferencia, int numeroFila) throws Exception { if (numeroFilaReferencia == numeroFila) return; XSSFRow xssfrowReferencia = hoja.getRow(numeroFilaReferencia); XSSFRow xssfrow = hoja.createRow(numeroFila); xssfrow.setHeight(xssfrowReferencia.getHeight()); } public void createRow (XSSFSheet sheet, int numeroFilaReferencia, int numeroFila, int numeroColumnas) throws Exception { createRow(sheet, numeroFilaReferencia, numeroFila, numeroColumnas, false); } public void createRow (XSSFSheet sheet, int numeroFilaReferencia, int numeroFila, int numeroColumnas, boolean copycontent) throws Exception { // Creamos la fila if (numeroFilaReferencia == numeroFila) return; XSSFRow sourceRow = sheet.getRow(numeroFilaReferencia); XSSFRow destinationRow = sheet.createRow(numeroFila); destinationRow.setHeight(sourceRow.getHeight()); for (int i=0; i