| Line | Hits | Source |
|---|---|---|
| 1 | /******************************************************************************* | |
| 2 | * Demetrix process modelling system | |
| 3 | * | |
| 4 | * Copyright (c) 2003, 2004 Dimitri A. Pissarenko | |
| 5 | * | |
| 6 | * This file is part of Demetrix. | |
| 7 | * | |
| 8 | * Demetrix is free software; you can redistribute it and/or modify | |
| 9 | * it under the terms of the GNU General Public License as published by | |
| 10 | * the Free Software Foundation; either version 2.1 of the License, or | |
| 11 | * (at your option) any later version. | |
| 12 | * | |
| 13 | * Demetrix is distributed in the hope that it will be useful, | |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 16 | * GNU General Public License for more details. | |
| 17 | * | |
| 18 | * You should have received a copy of the GNU General Public License | |
| 19 | * along with Demetrix; if not, write to the Free Software | |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 21 | * | |
| 22 | * For further information you may | |
| 23 | * | |
| 24 | * - send an e-mail in Russian, German or English to dimitri.pissarenko@gmx.net | |
| 25 | * - look at http://sourceforge.net/projects/demetrix/ | |
| 26 | * - look at http://demetrix.sourceforge.net/ | |
| 27 | * - look at http://members.inode.at/d.pissarenko/ | |
| 28 | * | |
| 29 | *****************************************************************************/ | |
| 30 | /* | |
| 31 | * Created on 24.01.2004 | |
| 32 | */ | |
| 33 | package net.sourceforge.demetrix.rio; | |
| 34 | ||
| 35 | import java.util.Iterator; | |
| 36 | ||
| 37 | import org.apache.log4j.Logger; | |
| 38 | import org.apache.poi.hssf.usermodel.HSSFCell; | |
| 39 | import org.apache.poi.hssf.usermodel.HSSFRow; | |
| 40 | import org.apache.poi.hssf.usermodel.HSSFSheet; | |
| 41 | ||
| 42 | /** | |
| 43 | * @author Dimitri Pissarenko | |
| 44 | * | |
| 45 | */ | |
| 46 | public class Excel2MaximaConverter { | |
| 47 | private Logger logger = Logger.getLogger(getClass()); | |
| 48 | public final static String EMPTY_ROW = "[]"; | |
| 49 | 5 | public Excel2MaximaConverter() { |
| 50 | 5 | } |
| 51 | public String convertToMaxima(HSSFSheet workSheet) { | |
| 52 | 1 | String lineSeparator = null; |
| 53 | 1 | String returnValue = null; |
| 54 | ||
| 55 | 1 | lineSeparator = System.getProperty("line.separator"); |
| 56 | 1 | returnValue = "A:matrix(" + lineSeparator; |
| 57 | 1 | returnValue = |
| 58 | returnValue | |
| 59 | + this.getMaximaRepresentation(workSheet) | |
| 60 | + lineSeparator; | |
| 61 | 1 | returnValue = returnValue + ");"; |
| 62 | ||
| 63 | 1 | return returnValue; |
| 64 | } | |
| 65 | public String getMaximaRepresentation(HSSFSheet workSheet) { | |
| 66 | 2 | StringBuffer matrix = null; |
| 67 | 2 | Iterator rows = null; |
| 68 | 2 | Iterator cells = null; |
| 69 | 2 | HSSFRow row = null; |
| 70 | 2 | HSSFCell cell = null; |
| 71 | 2 | String lineSeparator = null; |
| 72 | 2 | StringBuffer rowStringBuffer = null; |
| 73 | ||
| 74 | 2 | lineSeparator = System.getProperty("line.separator"); |
| 75 | 2 | matrix = new StringBuffer(); |
| 76 | ||
| 77 | 6 | for (short i = 0; i <= workSheet.getLastRowNum(); i++) { |
| 78 | 4 | row = (HSSFRow) workSheet.getRow(i); |
| 79 | 4 | rowStringBuffer = this.getMatrixRow(row); |
| 80 | 4 | if (matrix.length() > 0) { |
| 81 | 2 | matrix.append(','); |
| 82 | 2 | matrix.append(lineSeparator); |
| 83 | } | |
| 84 | 4 | matrix.append(rowStringBuffer); |
| 85 | } | |
| 86 | ||
| 87 | 2 | return matrix.toString(); |
| 88 | } | |
| 89 | private StringBuffer getMatrixRow(HSSFRow row) { | |
| 90 | 7 | StringBuffer returnValue = null; |
| 91 | 7 | StringBuffer cellContent = null; |
| 92 | 7 | Iterator cellIterator = null; |
| 93 | 7 | HSSFCell cell = null; |
| 94 | ||
| 95 | 7 | returnValue = new StringBuffer(); |
| 96 | 7 | returnValue.append('['); |
| 97 | 7 | if (row != null) { |
| 98 | 6 | cellIterator = row.cellIterator(); |
| 99 | ||
| 100 | 6 | for (short i = row.getFirstCellNum(); |
| 101 | 21 | i <= row.getLastCellNum(); |
| 102 | 15 | i++) { |
| 103 | 15 | cell = row.getCell(i); |
| 104 | 15 | cellContent = this.getMatrixCell(cell); |
| 105 | 15 | if (cellContent.length() > 0) |
| 106 | { | |
| 107 | 14 | if (returnValue.length() > 1) { |
| 108 | 8 | returnValue.append(','); |
| 109 | } | |
| 110 | ||
| 111 | 14 | returnValue.append(cellContent); |
| 112 | } | |
| 113 | ||
| 114 | } | |
| 115 | } | |
| 116 | ||
| 117 | 7 | returnValue.append(']'); |
| 118 | 7 | return returnValue; |
| 119 | } | |
| 120 | private StringBuffer getMatrixCell(HSSFCell cell) { | |
| 121 | 18 | StringBuffer returnValue = null; |
| 122 | 18 | returnValue = new StringBuffer(); |
| 123 | 18 | if (cell != null) { |
| 124 | 17 | if (cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) { |
| 125 | 10 | returnValue.append(cell.getNumericCellValue()); |
| 126 | 7 | } else if (cell.getCellType() == HSSFCell.CELL_TYPE_STRING) { |
| 127 | 6 | returnValue.append(cell.getStringCellValue()); |
| 128 | } | |
| 129 | } | |
| 130 | 18 | return returnValue; |
| 131 | } | |
| 132 | } |
|
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |