| 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ |
| 2 | /* librevenge |
| 3 | * Version: MPL 2.0 / LGPLv2.1+ |
| 4 | * |
| 5 | * This Source Code Form is subject to the terms of the Mozilla Public |
| 6 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 7 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 8 | * |
| 9 | * Major Contributor(s): |
| 10 | * Copyright (C) 2002 William Lachance ([email protected]) |
| 11 | * Copyright (C) 2002-2003 Marc Maurer ([email protected]) |
| 12 | * |
| 13 | * For minor contributions see the git repository. |
| 14 | * |
| 15 | * Alternatively, the contents of this file may be used under the terms |
| 16 | * of the GNU Lesser General Public License Version 2.1 or later |
| 17 | * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are |
| 18 | * applicable instead of those above. |
| 19 | */ |
| 20 | |
| 21 | #include <librevenge-generators/librevenge-generators.h> |
| 22 | |
| 23 | #include <time.h> |
| 24 | |
| 25 | #include <string> |
| 26 | #include <sstream> |
| 27 | #include <vector> |
| 28 | |
| 29 | #include "librevenge_internal.h" |
| 30 | |
| 31 | namespace librevenge |
| 32 | { |
| 33 | |
| 34 | struct RVNGCSVSpreadsheetRowContent |
| 35 | { |
| 36 | //!constructor |
| 37 | RVNGCSVSpreadsheetRowContent() : m_content(""), m_numFields(0), m_numRepeated(1) |
| 38 | { |
| 39 | } |
| 40 | //! the content |
| 41 | std::string m_content; |
| 42 | //! the number of fields |
| 43 | int m_numFields; |
| 44 | //! the number of repetition |
| 45 | int m_numRepeated; |
| 46 | }; |
| 47 | |
| 48 | struct RVNGCSVSpreadsheetGeneratorImpl |
| 49 | { |
| 50 | explicit RVNGCSVSpreadsheetGeneratorImpl(RVNGStringVector &sheets, bool useFormula) : |
| 51 | m_sheets(sheets), m_rowStream(), m_cellStream(), m_rowContentsList(), |
| 52 | m_numRowRepeated(0), m_numCellRepeated(0), m_numCellToSkip(0), |
| 53 | m_useFormula(useFormula), |
| 54 | m_fieldSeparator(','), m_textSeparator('"'), m_decimalSeparator('.'), |
| 55 | m_dateFormat("%m/%d/%y"), m_timeFormat("%H:%M:%S"), |
| 56 | m_inSheet(false), m_inSheetRow(false), m_inSheetCell(false), m_sheetCellHasFormula(false), |
| 57 | m_numberSubForm(0), |
| 58 | m_column(0), m_row(0), m_numColumns(0), m_numColumnsInRowStream(0) {} |
| 59 | bool canWriteData(bool newCell=false) const |
| 60 | { |
| 61 | if (!m_inSheet || !m_inSheetRow || m_numberSubForm) return false; |
| 62 | if (newCell) return true; |
| 63 | return m_inSheetCell && !m_sheetCellHasFormula; |
| 64 | } |
| 65 | void insertCharacter(char c) |
| 66 | { |
| 67 | if (c==m_textSeparator) |
| 68 | m_cellStream << m_textSeparator; |
| 69 | m_cellStream << c; |
| 70 | } |
| 71 | void insertDouble(double val) |
| 72 | { |
| 73 | std::stringstream s; |
| 74 | s << val; |
| 75 | std::string res=s.str(); |
| 76 | if (m_decimalSeparator!='.') |
| 77 | { |
| 78 | std::string::size_type pos = res.find_last_of('.'); |
| 79 | if (pos != std::string::npos) res[pos]=m_decimalSeparator; |
| 80 | } |
| 81 | m_cellStream << res; |
| 82 | } |
| 83 | void insertInstruction(librevenge::RVNGPropertyList const &instruction); |
| 84 | void storeActualSpreadsheet(); |
| 85 | RVNGStringVector &m_sheets; |
| 86 | //! the actual row stream |
| 87 | std::ostringstream m_rowStream; |
| 88 | //! the actual cell stream |
| 89 | std::ostringstream m_cellStream; |
| 90 | //! the content of each row |
| 91 | std::vector<RVNGCSVSpreadsheetRowContent> m_rowContentsList; |
| 92 | //! the number of repetition of the actual row |
| 93 | int m_numRowRepeated; |
| 94 | //! the number of repetition of the actual cell |
| 95 | int m_numCellRepeated; |
| 96 | //! the number of empty cell which follow current cell |
| 97 | int m_numCellToSkip; |
| 98 | bool m_useFormula; |
| 99 | char m_fieldSeparator, m_textSeparator, m_decimalSeparator; |
| 100 | std::string m_dateFormat, m_timeFormat; |
| 101 | bool m_inSheet, m_inSheetRow, m_inSheetCell, m_sheetCellHasFormula; |
| 102 | int m_numberSubForm; |
| 103 | int m_column/** the current column*/, m_row/*the current row*/, m_numColumns/**the total number of column*/; |
| 104 | int m_numColumnsInRowStream/** the number of column written in rowStream*/; |
| 105 | }; |
| 106 | |
| 107 | void RVNGCSVSpreadsheetGeneratorImpl::insertInstruction(librevenge::RVNGPropertyList const &instr) |
| 108 | { |
| 109 | if (!instr["librevenge:type"]) |
| 110 | { |
| 111 | RVNG_DEBUG_MSG(("RVNGCSVSpreadsheetGeneratorImpl::insertInstruction can not find formula type !!!\n")); |
| 112 | return; |
| 113 | } |
| 114 | std::string type(instr["librevenge:type"]->getStr().cstr()); |
| 115 | if (type=="librevenge-operator") |
| 116 | { |
| 117 | if (!instr["librevenge:operator"]) |
| 118 | { |
| 119 | RVNG_DEBUG_MSG(("RVNGCSVSpreadsheetGeneratorImpl::insertInstruction can not find operator for formula!!!\n")); |
| 120 | return; |
| 121 | } |
| 122 | m_cellStream << instr["librevenge:operator"]->getStr().cstr(); |
| 123 | return; |
| 124 | } |
| 125 | if (type=="librevenge-function") |
| 126 | { |
| 127 | if (!instr["librevenge:function"]) |
| 128 | { |
| 129 | RVNG_DEBUG_MSG(("RVNGCSVSpreadsheetGeneratorImpl::insertInstruction can not find function for formula!!!\n")); |
| 130 | return; |
| 131 | } |
| 132 | m_cellStream << instr["librevenge:function"]->getStr().cstr(); |
| 133 | return; |
| 134 | } |
| 135 | if (type=="librevenge-number") |
| 136 | { |
| 137 | if (!instr["librevenge:number"]) |
| 138 | { |
| 139 | RVNG_DEBUG_MSG(("RVNGCSVSpreadsheetGeneratorImpl::insertInstruction can not find value for formula!!!\n")); |
| 140 | return; |
| 141 | } |
| 142 | insertDouble(instr["librevenge:number"]->getDouble()); |
| 143 | return; |
| 144 | } |
| 145 | if (type=="librevenge-text") |
| 146 | { |
| 147 | if (!instr["librevenge:text"]) |
| 148 | { |
| 149 | RVNG_DEBUG_MSG(("RVNGCSVSpreadsheetGeneratorImpl::insertInstruction can not find text for formula!!!\n")); |
| 150 | return; |
| 151 | } |
| 152 | std::string text(instr["librevenge:text"]->getStr().cstr()); |
| 153 | insertCharacter('"'); |
| 154 | for (char t : text) |
| 155 | insertCharacter(t); |
| 156 | insertCharacter('"'); |
| 157 | return; |
| 158 | } |
| 159 | if (type=="librevenge-cell") |
| 160 | { |
| 161 | if (!instr["librevenge:row"]||!instr["librevenge:column"]) |
| 162 | { |
| 163 | RVNG_DEBUG_MSG(("RVNGCSVSpreadsheetGeneratorImpl::insertInstruction can not find formula cordinate!!!\n")); |
| 164 | return; |
| 165 | } |
| 166 | int column=instr["librevenge:column"]->getInt(); |
| 167 | // we need to add 1 because we have added an header row |
| 168 | int row=instr["librevenge:row"]->getInt()+1; |
| 169 | if (column<0 || row<0) |
| 170 | { |
| 171 | RVNG_DEBUG_MSG(("RVNGCSVSpreadsheetGeneratorImpl::insertInstruction: find bad coordinate for formula!!!\n")); |
| 172 | return; |
| 173 | } |
| 174 | if (instr["librevenge:column-absolute"] && instr["librevenge:column-absolute"]->getInt()) m_cellStream << "$"; |
| 175 | if (column>=26) m_cellStream << char('A'+(column/26-1)); |
| 176 | m_cellStream << char('A'+(column%26)); |
| 177 | if (instr["librevenge:row-absolute"] && instr["librevenge:row-absolute"]->getInt()) m_cellStream << "$"; |
| 178 | m_cellStream << row+1; |
| 179 | return; |
| 180 | } |
| 181 | if (type=="librevenge-cells") |
| 182 | { |
| 183 | if (!instr["librevenge:start-row"]||!instr["librevenge:start-column"]) |
| 184 | { |
| 185 | RVNG_DEBUG_MSG(("RVNGCSVSpreadsheetGeneratorImpl::insertInstruction can not find formula cordinate!!!\n")); |
| 186 | return; |
| 187 | } |
| 188 | int column=instr["librevenge:start-column"]->getInt(); |
| 189 | // we need to add 1 because we have added an header row |
| 190 | int row=instr["librevenge:start-row"]->getInt()+1; |
| 191 | if (column<0 || row<0) |
| 192 | { |
| 193 | RVNG_DEBUG_MSG(("RVNGCSVSpreadsheetGeneratorImpl::insertInstruction: find bad coordinate1 for formula!!!\n")); |
| 194 | return; |
| 195 | } |
| 196 | if (instr["librevenge:start-column-absolute"] && instr["librevenge:start-column-absolute"]->getInt()) m_cellStream << "$"; |
| 197 | if (column>=26) m_cellStream << char('A'+(column/26-1)); |
| 198 | m_cellStream << char('A'+(column%26)); |
| 199 | if (instr["librevenge:start-row-absolute"] && instr["librevenge:start-row-absolute"]->getInt()) m_cellStream << "$"; |
| 200 | m_cellStream << row+1 << ":"; |
| 201 | if (instr["librevenge:end-column"]) |
| 202 | column=instr["librevenge:end-column"]->getInt(); |
| 203 | // we need to add 1 because we have added an header row |
| 204 | if (instr["librevenge:end-row"]) |
| 205 | row=instr["librevenge:end-row"]->getInt()+1; |
| 206 | if (column<0 || row<0) |
| 207 | { |
| 208 | RVNG_DEBUG_MSG(("RVNGCSVSpreadsheetGeneratorImpl::insertInstruction: find bad coordinate2 for formula!!!\n")); |
| 209 | return; |
| 210 | } |
| 211 | if (instr["librevenge:end-column-absolute"] && instr["librevenge:end-column-absolute"]->getInt()) m_cellStream << "$"; |
| 212 | if (column>=26) m_cellStream << char('A'+(column/26-1)); |
| 213 | m_cellStream << char('A'+(column%26)); |
| 214 | if (instr["librevenge:end-row-absolute"] && instr["librevenge:end-row-absolute"]->getInt()) m_cellStream << "$"; |
| 215 | m_cellStream << row+1; |
| 216 | return; |
| 217 | } |
| 218 | RVNG_DEBUG_MSG(("RVNGCSVSpreadsheetGeneratorImpl::insertInstruction find unknown type %s!!!\n", type.c_str())); |
| 219 | } |
| 220 | |
| 221 | void RVNGCSVSpreadsheetGeneratorImpl::storeActualSpreadsheet() |
| 222 | { |
| 223 | std::stringstream stream; |
| 224 | for (int i=0; i < m_numColumns; ++i) |
| 225 | { |
| 226 | if (i) |
| 227 | stream << m_fieldSeparator; |
| 228 | stream << "Col" << i+1; |
| 229 | } |
| 230 | stream << "\n"; |
| 231 | |
| 232 | // first find the last row which contains some data |
| 233 | size_t numNotEmptyRow=0; |
| 234 | for (size_t i=m_rowContentsList.size(); i>0; --i) |
| 235 | { |
| 236 | if (m_rowContentsList[i-1].m_numFields) |
| 237 | { |
| 238 | numNotEmptyRow=i; |
| 239 | break; |
| 240 | } |
| 241 | } |
| 242 | for (size_t i=0; i<numNotEmptyRow; ++i) |
| 243 | { |
| 244 | RVNGCSVSpreadsheetRowContent const &row=m_rowContentsList[i]; |
| 245 | if (row.m_numRepeated<=0) continue; |
| 246 | m_rowStream.str(""); |
| 247 | m_rowStream << row.m_content; |
| 248 | // add empty cells |
| 249 | for (int c=row.m_numFields; c < m_numColumns; ++c) |
| 250 | { |
| 251 | if (c) |
| 252 | m_rowStream << m_fieldSeparator; |
| 253 | m_rowStream << m_textSeparator << m_textSeparator; |
| 254 | } |
| 255 | m_rowStream << "\n"; |
| 256 | for (int r=0; r<row.m_numRepeated; ++r) |
| 257 | stream << m_rowStream.str(); |
| 258 | } |
| 259 | m_sheets.append(stream.str().c_str()); |
| 260 | } |
| 261 | |
| 262 | RVNGCSVSpreadsheetGenerator::RVNGCSVSpreadsheetGenerator(RVNGStringVector &sheets, bool generateFormula) : |
| 263 | m_impl(new RVNGCSVSpreadsheetGeneratorImpl(sheets,generateFormula)) |
| 264 | { |
| 265 | } |
| 266 | |
| 267 | RVNGCSVSpreadsheetGenerator::~RVNGCSVSpreadsheetGenerator() |
| 268 | { |
| 269 | delete m_impl; |
| 270 | } |
| 271 | |
| 272 | void RVNGCSVSpreadsheetGenerator::setSeparators(char fieldSep, char textSep, char decimalSep) |
| 273 | { |
| 274 | m_impl->m_fieldSeparator=fieldSep; |
| 275 | m_impl->m_textSeparator=textSep; |
| 276 | m_impl->m_decimalSeparator=decimalSep; |
| 277 | } |
| 278 | |
| 279 | void RVNGCSVSpreadsheetGenerator::setDTFormats(RVNGString const &date, RVNGString const &time) |
| 280 | { |
| 281 | m_impl->m_dateFormat=date.cstr(); |
| 282 | m_impl->m_timeFormat=time.cstr(); |
| 283 | } |
| 284 | |
| 285 | void RVNGCSVSpreadsheetGenerator::setDocumentMetaData(const RVNGPropertyList &) {} |
| 286 | void RVNGCSVSpreadsheetGenerator::defineEmbeddedFont(const RVNGPropertyList &) {} |
| 287 | void RVNGCSVSpreadsheetGenerator::startDocument(const RVNGPropertyList &) {} |
| 288 | void RVNGCSVSpreadsheetGenerator::endDocument() {} |
| 289 | |
| 290 | void RVNGCSVSpreadsheetGenerator::defineSheetNumberingStyle(const RVNGPropertyList &) {} |
| 291 | |
| 292 | void RVNGCSVSpreadsheetGenerator::openSheet(const RVNGPropertyList &) |
| 293 | { |
| 294 | if (m_impl->m_numberSubForm || m_impl->m_inSheet) |
| 295 | { |
| 296 | ++m_impl->m_numberSubForm; |
| 297 | return; |
| 298 | } |
| 299 | m_impl->m_inSheet=true; |
| 300 | m_impl->m_row = m_impl->m_column = 0; |
| 301 | m_impl->m_numColumns = 0; |
| 302 | } |
| 303 | |
| 304 | void RVNGCSVSpreadsheetGenerator::closeSheet() |
| 305 | { |
| 306 | if (m_impl->m_numberSubForm) |
| 307 | { |
| 308 | --m_impl->m_numberSubForm; |
| 309 | return; |
| 310 | } |
| 311 | m_impl->storeActualSpreadsheet(); |
| 312 | m_impl->m_inSheet=false; |
| 313 | } |
| 314 | |
| 315 | void RVNGCSVSpreadsheetGenerator::openSheetRow(const RVNGPropertyList &propList) |
| 316 | { |
| 317 | if (m_impl->m_numberSubForm || !m_impl->m_inSheet || m_impl->m_inSheetRow) |
| 318 | { |
| 319 | ++m_impl->m_numberSubForm; |
| 320 | return; |
| 321 | } |
| 322 | int row = propList["librevenge:row"] ? propList["librevenge:row"]->getInt() : m_impl->m_row; |
| 323 | if (m_impl->m_row < row) |
| 324 | { |
| 325 | m_impl->m_rowContentsList.push_back(RVNGCSVSpreadsheetRowContent()); |
| 326 | m_impl->m_rowContentsList.back().m_numRepeated=row-m_impl->m_row; |
| 327 | } |
| 328 | m_impl->m_rowStream.str(""); |
| 329 | if (propList["table:number-rows-repeated"] && propList["table:number-rows-repeated"]->getInt()>1) |
| 330 | m_impl->m_numRowRepeated=propList["table:number-rows-repeated"]->getInt(); |
| 331 | else |
| 332 | m_impl->m_numRowRepeated=1; |
| 333 | m_impl->m_inSheetRow=true; |
| 334 | m_impl->m_row = row; |
| 335 | m_impl->m_column = m_impl->m_numColumnsInRowStream = 0; |
| 336 | } |
| 337 | |
| 338 | void RVNGCSVSpreadsheetGenerator::closeSheetRow() |
| 339 | { |
| 340 | if (m_impl->m_numberSubForm) |
| 341 | { |
| 342 | --m_impl->m_numberSubForm; |
| 343 | return; |
| 344 | } |
| 345 | m_impl->m_rowContentsList.push_back(RVNGCSVSpreadsheetRowContent()); |
| 346 | RVNGCSVSpreadsheetRowContent &row=m_impl->m_rowContentsList.back(); |
| 347 | row.m_content=m_impl->m_rowStream.str(); |
| 348 | row.m_numFields=m_impl->m_numColumnsInRowStream; |
| 349 | row.m_numRepeated=m_impl->m_numRowRepeated; |
| 350 | if (m_impl->m_numColumnsInRowStream>m_impl->m_numColumns) |
| 351 | m_impl->m_numColumns=m_impl->m_numColumnsInRowStream; |
| 352 | m_impl->m_row+=m_impl->m_numRowRepeated; |
| 353 | m_impl->m_numRowRepeated=0; |
| 354 | m_impl->m_inSheetRow=false; |
| 355 | } |
| 356 | |
| 357 | void RVNGCSVSpreadsheetGenerator::openSheetCell(const RVNGPropertyList &propList) |
| 358 | { |
| 359 | if (m_impl->m_numberSubForm || !m_impl->m_inSheetRow || m_impl->m_inSheetCell) |
| 360 | { |
| 361 | ++m_impl->m_numberSubForm; |
| 362 | return; |
| 363 | } |
| 364 | int column = propList["librevenge:column"] ? propList["librevenge:column"]->getInt() : m_impl->m_column; |
| 365 | m_impl->m_column=column; |
| 366 | m_impl->m_inSheetCell=true; |
| 367 | m_impl->m_sheetCellHasFormula=false; |
| 368 | m_impl->m_cellStream.str(""); |
| 369 | if (propList["table:number-columns-repeated"] && propList["table:number-columns-repeated"]->getInt()>1) |
| 370 | m_impl->m_numCellRepeated=propList["table:number-columns-repeated"]->getInt(); |
| 371 | else |
| 372 | m_impl->m_numCellRepeated=1; |
| 373 | if (propList["table:number-columns-spanned"] && propList["table:number-columns-spanned"]->getInt()>1) |
| 374 | m_impl->m_numCellToSkip=propList["table:number-columns-spanned"]->getInt()-1; |
| 375 | else |
| 376 | m_impl->m_numCellToSkip=0; |
| 377 | if (propList["table:number-matrix-columns-spanned"] && propList["table:number-matrix-columns-spanned"]->getInt()>1) |
| 378 | m_impl->m_numCellToSkip+=propList["table:number-matrix-columns-spanned"]->getInt()-1; |
| 379 | if (m_impl->m_useFormula) |
| 380 | { |
| 381 | librevenge::RVNGPropertyListVector const *formula=propList.child("librevenge:formula"); |
| 382 | if (formula && formula->count()) |
| 383 | { |
| 384 | m_impl->m_sheetCellHasFormula=true; |
| 385 | m_impl->insertCharacter('='); |
| 386 | for (unsigned long s=0; s<formula->count(); ++s) |
| 387 | m_impl->insertInstruction((*formula)[s]); |
| 388 | return; |
| 389 | } |
| 390 | } |
| 391 | if (!propList["librevenge:value-type"]) return; |
| 392 | |
| 393 | // now we need to retrieve the value in proplist |
| 394 | std::string valueType(propList["librevenge:value-type"]->getStr().cstr()); |
| 395 | if (valueType=="double" || valueType=="scientific") valueType="float"; |
| 396 | else if (valueType=="percent") valueType="percentage"; |
| 397 | |
| 398 | if (propList["librevenge:value"] && (valueType=="float" || valueType=="percentage" || valueType=="currency")) |
| 399 | { |
| 400 | if (valueType=="percentage") |
| 401 | { |
| 402 | m_impl->insertDouble(100. * propList["librevenge:value"]->getDouble()); |
| 403 | m_impl->m_cellStream << "%"; |
| 404 | } |
| 405 | else |
| 406 | { |
| 407 | // if (valueType=="currency") m_impl->m_cellStream << "$"; |
| 408 | m_impl->insertDouble(propList["librevenge:value"]->getDouble()); |
| 409 | } |
| 410 | } |
| 411 | else if (propList["librevenge:value"] && (valueType=="bool" || valueType=="boolean")) |
| 412 | { |
| 413 | if (propList["librevenge:value"]->getDouble()<0||propList["librevenge:value"]->getDouble()>0) |
| 414 | m_impl->m_cellStream << "true"; |
| 415 | else |
| 416 | m_impl->m_cellStream << "false"; |
| 417 | } |
| 418 | else if (valueType=="date" || valueType=="time") |
| 419 | { |
| 420 | // checkme |
| 421 | struct tm time; |
| 422 | time.tm_sec=time.tm_min=time.tm_hour=0; |
| 423 | time.tm_mday=time.tm_mon=1; |
| 424 | time.tm_year=100; |
| 425 | time.tm_wday=time.tm_yday=time.tm_isdst=-1; |
| 426 | char buf[256]; |
| 427 | if (valueType=="date") |
| 428 | { |
| 429 | time.tm_mday=propList["librevenge:day"] ? propList["librevenge:day"]->getInt() : 1; |
| 430 | time.tm_mon=propList["librevenge:month"] ? propList["librevenge:month"]->getInt()-1 : 0; |
| 431 | time.tm_year=propList["librevenge:year"] ? propList["librevenge:year"]->getInt()-1900 : 100; |
| 432 | if (mktime(&time)!=-1 && strftime(buf, 256, m_impl->m_dateFormat.c_str(), &time)) |
| 433 | m_impl->m_cellStream << buf; |
| 434 | } |
| 435 | else |
| 436 | { |
| 437 | time.tm_hour=propList["librevenge:hours"] ? propList["librevenge:hours"]->getInt() : 0; |
| 438 | time.tm_min=propList["librevenge:minutes"] ? propList["librevenge:minutes"]->getInt() : 0; |
| 439 | time.tm_sec=propList["librevenge:seconds"] ? propList["librevenge:seconds"]->getInt() : 0; |
| 440 | if (mktime(&time)!=-1 && strftime(buf, 256, m_impl->m_timeFormat.c_str(), &time)) |
| 441 | m_impl->m_cellStream << buf; |
| 442 | } |
| 443 | } |
| 444 | else if (valueType!="string" && valueType!="text") |
| 445 | { |
| 446 | RVNG_DEBUG_MSG(("RVNGCSVSpreadsheetGenerator::openSheetCell: unexpected value type: %s\n", valueType.c_str())); |
| 447 | } |
| 448 | } |
| 449 | |
| 450 | void RVNGCSVSpreadsheetGenerator::closeSheetCell() |
| 451 | { |
| 452 | if (m_impl->m_numberSubForm) |
| 453 | { |
| 454 | --m_impl->m_numberSubForm; |
| 455 | return; |
| 456 | } |
| 457 | |
| 458 | m_impl->m_inSheetCell=false; |
| 459 | if (m_impl->m_cellStream.str().empty()) |
| 460 | { |
| 461 | m_impl->m_column+=m_impl->m_numCellRepeated+m_impl->m_numCellToSkip; |
| 462 | return; |
| 463 | } |
| 464 | // time to add the empty cell |
| 465 | for (int i=m_impl->m_numColumnsInRowStream; i < m_impl->m_column; ++i) |
| 466 | { |
| 467 | if (i) |
| 468 | m_impl->m_rowStream << m_impl->m_fieldSeparator; |
| 469 | m_impl->m_rowStream << m_impl->m_textSeparator << m_impl->m_textSeparator; |
| 470 | } |
| 471 | // add the current cell |
| 472 | for (int i=0; i<m_impl->m_numCellRepeated; ++i) |
| 473 | { |
| 474 | if (i || m_impl->m_column) |
| 475 | m_impl->m_rowStream << m_impl->m_fieldSeparator; |
| 476 | m_impl->m_rowStream << m_impl->m_textSeparator << m_impl->m_cellStream.str() << m_impl->m_textSeparator; |
| 477 | } |
| 478 | m_impl->m_numColumnsInRowStream = m_impl->m_column+m_impl->m_numCellRepeated; |
| 479 | m_impl->m_column=m_impl->m_numColumnsInRowStream+m_impl->m_numCellToSkip; |
| 480 | } |
| 481 | |
| 482 | void RVNGCSVSpreadsheetGenerator::defineChartStyle(const RVNGPropertyList &) {} |
| 483 | void RVNGCSVSpreadsheetGenerator::openChart(const RVNGPropertyList &) |
| 484 | { |
| 485 | ++m_impl->m_numberSubForm; |
| 486 | } |
| 487 | void RVNGCSVSpreadsheetGenerator::closeChart() |
| 488 | { |
| 489 | --m_impl->m_numberSubForm; |
| 490 | } |
| 491 | void RVNGCSVSpreadsheetGenerator::openChartTextObject(const RVNGPropertyList &) {} |
| 492 | void RVNGCSVSpreadsheetGenerator::closeChartTextObject() {} |
| 493 | void RVNGCSVSpreadsheetGenerator::openChartPlotArea(const RVNGPropertyList &) {} |
| 494 | void RVNGCSVSpreadsheetGenerator::closeChartPlotArea() {} |
| 495 | void RVNGCSVSpreadsheetGenerator::insertChartAxis(const RVNGPropertyList &) {} |
| 496 | void RVNGCSVSpreadsheetGenerator::openChartSerie(const RVNGPropertyList &) {} |
| 497 | void RVNGCSVSpreadsheetGenerator::closeChartSerie() {} |
| 498 | |
| 499 | void RVNGCSVSpreadsheetGenerator::definePageStyle(const RVNGPropertyList &) {} |
| 500 | void RVNGCSVSpreadsheetGenerator::openPageSpan(const RVNGPropertyList &) {} |
| 501 | void RVNGCSVSpreadsheetGenerator::closePageSpan() {} |
| 502 | void RVNGCSVSpreadsheetGenerator::openHeader(const RVNGPropertyList &) |
| 503 | { |
| 504 | ++m_impl->m_numberSubForm; |
| 505 | } |
| 506 | void RVNGCSVSpreadsheetGenerator::closeHeader() |
| 507 | { |
| 508 | --m_impl->m_numberSubForm; |
| 509 | } |
| 510 | void RVNGCSVSpreadsheetGenerator::openFooter(const RVNGPropertyList &) |
| 511 | { |
| 512 | ++m_impl->m_numberSubForm; |
| 513 | } |
| 514 | void RVNGCSVSpreadsheetGenerator::closeFooter() |
| 515 | { |
| 516 | --m_impl->m_numberSubForm; |
| 517 | } |
| 518 | |
| 519 | |
| 520 | void RVNGCSVSpreadsheetGenerator::defineSectionStyle(const RVNGPropertyList &) {} |
| 521 | void RVNGCSVSpreadsheetGenerator::openSection(const RVNGPropertyList &) {} |
| 522 | void RVNGCSVSpreadsheetGenerator::closeSection() {} |
| 523 | |
| 524 | void RVNGCSVSpreadsheetGenerator::defineParagraphStyle(const RVNGPropertyList &) {} |
| 525 | void RVNGCSVSpreadsheetGenerator::openParagraph(const RVNGPropertyList &) {} |
| 526 | void RVNGCSVSpreadsheetGenerator::closeParagraph() {} |
| 527 | |
| 528 | void RVNGCSVSpreadsheetGenerator::defineCharacterStyle(const RVNGPropertyList &) {} |
| 529 | void RVNGCSVSpreadsheetGenerator::openSpan(const RVNGPropertyList &) {} |
| 530 | void RVNGCSVSpreadsheetGenerator::closeSpan() {} |
| 531 | |
| 532 | void RVNGCSVSpreadsheetGenerator::openLink(const RVNGPropertyList &) {} |
| 533 | void RVNGCSVSpreadsheetGenerator::closeLink() {} |
| 534 | |
| 535 | void RVNGCSVSpreadsheetGenerator::insertTab() |
| 536 | { |
| 537 | if (!m_impl->canWriteData()) |
| 538 | return; |
| 539 | m_impl->insertCharacter('\t'); |
| 540 | } |
| 541 | |
| 542 | void RVNGCSVSpreadsheetGenerator::insertText(const RVNGString &text) |
| 543 | { |
| 544 | if (!m_impl->canWriteData()) |
| 545 | return; |
| 546 | char const *data=text.cstr(); |
| 547 | for (unsigned long c=0; c<text.size(); ++c) |
| 548 | m_impl->insertCharacter(data[c]); |
| 549 | } |
| 550 | |
| 551 | void RVNGCSVSpreadsheetGenerator::insertSpace() |
| 552 | { |
| 553 | if (!m_impl->canWriteData()) |
| 554 | return; |
| 555 | m_impl->insertCharacter(' '); |
| 556 | } |
| 557 | |
| 558 | void RVNGCSVSpreadsheetGenerator::insertLineBreak() |
| 559 | { |
| 560 | if (!m_impl->canWriteData()) |
| 561 | return; |
| 562 | m_impl->insertCharacter(' '); |
| 563 | } |
| 564 | |
| 565 | void RVNGCSVSpreadsheetGenerator::insertField(const RVNGPropertyList &) {} |
| 566 | |
| 567 | void RVNGCSVSpreadsheetGenerator::openOrderedListLevel(const RVNGPropertyList &) {} |
| 568 | void RVNGCSVSpreadsheetGenerator::openUnorderedListLevel(const RVNGPropertyList &) {} |
| 569 | void RVNGCSVSpreadsheetGenerator::closeOrderedListLevel() {} |
| 570 | void RVNGCSVSpreadsheetGenerator::closeUnorderedListLevel() {} |
| 571 | void RVNGCSVSpreadsheetGenerator::openListElement(const RVNGPropertyList &) {} |
| 572 | void RVNGCSVSpreadsheetGenerator::closeListElement() {} |
| 573 | |
| 574 | void RVNGCSVSpreadsheetGenerator::openFootnote(const RVNGPropertyList &) |
| 575 | { |
| 576 | ++m_impl->m_numberSubForm; |
| 577 | } |
| 578 | void RVNGCSVSpreadsheetGenerator::closeFootnote() |
| 579 | { |
| 580 | --m_impl->m_numberSubForm; |
| 581 | } |
| 582 | void RVNGCSVSpreadsheetGenerator::openEndnote(const RVNGPropertyList &) |
| 583 | { |
| 584 | ++m_impl->m_numberSubForm; |
| 585 | } |
| 586 | void RVNGCSVSpreadsheetGenerator::closeEndnote() |
| 587 | { |
| 588 | --m_impl->m_numberSubForm; |
| 589 | } |
| 590 | void RVNGCSVSpreadsheetGenerator::openComment(const RVNGPropertyList &) |
| 591 | { |
| 592 | ++m_impl->m_numberSubForm; |
| 593 | } |
| 594 | void RVNGCSVSpreadsheetGenerator::closeComment() |
| 595 | { |
| 596 | --m_impl->m_numberSubForm; |
| 597 | } |
| 598 | void RVNGCSVSpreadsheetGenerator::openTextBox(const RVNGPropertyList &) |
| 599 | { |
| 600 | ++m_impl->m_numberSubForm; |
| 601 | } |
| 602 | void RVNGCSVSpreadsheetGenerator::closeTextBox() |
| 603 | { |
| 604 | --m_impl->m_numberSubForm; |
| 605 | } |
| 606 | |
| 607 | void RVNGCSVSpreadsheetGenerator::openTable(const RVNGPropertyList &) |
| 608 | { |
| 609 | ++m_impl->m_numberSubForm; |
| 610 | } |
| 611 | void RVNGCSVSpreadsheetGenerator::closeTable() |
| 612 | { |
| 613 | --m_impl->m_numberSubForm; |
| 614 | } |
| 615 | void RVNGCSVSpreadsheetGenerator::openTableRow(const RVNGPropertyList &) {} |
| 616 | void RVNGCSVSpreadsheetGenerator::closeTableRow() {} |
| 617 | void RVNGCSVSpreadsheetGenerator::openTableCell(const RVNGPropertyList &) {} |
| 618 | void RVNGCSVSpreadsheetGenerator::closeTableCell() {} |
| 619 | void RVNGCSVSpreadsheetGenerator::insertCoveredTableCell(const RVNGPropertyList &) {} |
| 620 | |
| 621 | void RVNGCSVSpreadsheetGenerator::openFrame(const RVNGPropertyList &) |
| 622 | { |
| 623 | ++m_impl->m_numberSubForm; |
| 624 | } |
| 625 | void RVNGCSVSpreadsheetGenerator::closeFrame() |
| 626 | { |
| 627 | --m_impl->m_numberSubForm; |
| 628 | } |
| 629 | |
| 630 | void RVNGCSVSpreadsheetGenerator::openGroup(const RVNGPropertyList &) |
| 631 | { |
| 632 | ++m_impl->m_numberSubForm; |
| 633 | } |
| 634 | void RVNGCSVSpreadsheetGenerator::closeGroup() |
| 635 | { |
| 636 | --m_impl->m_numberSubForm; |
| 637 | } |
| 638 | |
| 639 | void RVNGCSVSpreadsheetGenerator::defineGraphicStyle(const RVNGPropertyList &) {} |
| 640 | void RVNGCSVSpreadsheetGenerator::drawRectangle(const RVNGPropertyList &) {} |
| 641 | void RVNGCSVSpreadsheetGenerator::drawEllipse(const RVNGPropertyList &) {} |
| 642 | void RVNGCSVSpreadsheetGenerator::drawPolygon(const RVNGPropertyList &) {} |
| 643 | void RVNGCSVSpreadsheetGenerator::drawPolyline(const RVNGPropertyList &) {} |
| 644 | void RVNGCSVSpreadsheetGenerator::drawPath(const RVNGPropertyList &) {} |
| 645 | void RVNGCSVSpreadsheetGenerator::drawConnector(const RVNGPropertyList &) {} |
| 646 | |
| 647 | void RVNGCSVSpreadsheetGenerator::insertBinaryObject(const RVNGPropertyList &) {} |
| 648 | void RVNGCSVSpreadsheetGenerator::insertEquation(const RVNGPropertyList &) {} |
| 649 | |
| 650 | } |
| 651 | |
| 652 | /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */ |