Exemplo n.º 1
0
  static bool exportCSV(std::string const& filename)
  {
    std::ofstream file(filename.c_str());
    if (!file.is_open())
    {
      flashMessage("Could not save document!");
      return false;
    }

    // Write all the cells
    for (int y = 0; y < currentDoc().height_; ++y)
    {
      for (int x = 0; x < currentDoc().width_; ++x)
      {
        Cell const& cell = getCell(Index(x, y));

        file << getText(cell);

        if (x < (currentDoc().width_ - 1))
        {
          file << currentDoc().delimiter_;
        }
        else
        {
          if (y < (currentDoc().height_ - 1))
            file << std::endl;
        }
      }
    }

    return true;
  }
Exemplo n.º 2
0
  bool load(std::string const& filename)
  {
    std::ifstream file(filename.c_str());
    if (!file.is_open())
    {
      logError("Could not open document '", filename, "'");
      flashMessage("Could not open document!");
      return false;
    }

    std::string data = "";
    std::string line = "";
    while (std::getline(file, line))
      data += line + "\n";

    if (data.size() == 0)
    {
      logError("No data in file '", filename, "'");
      return false;
    }

    // Determin if we are reading a zum file, of a csv type of file.
    if (data.size() > 5 && data[0] == 'Z' && data[1] == 'U' && data[2] == 'M' && data[3] == '1' && data[4] == '\n')
    {
      if (!loadZum1(data))
      {
        logError("Could not parse document '", filename, "'");
        return false;
      }
    }
    else
    {
      if (!loadCSV(data, 0))
      {
        logError("Could not parse document '", filename, "'");
        return false;
      }
    }

    currentDoc().filename_ = filename;
    currentDoc().readOnly_ = false;

    return true;
  }
Exemplo n.º 3
0
void loop() {
    if (digitalRead(switchPin) == LOW) {
        flashMessage(message);
    }
}
Exemplo n.º 4
0
  bool save(std::string const& filename)
  {
    logInfo("Saving document: ", filename);

    std::ofstream file(filename.c_str());
    if (!file.is_open())
    {
      flashMessage("Could not save document!");
      return false;
    }


    // Collect and sort the cells, so they are saved in the same order
    std::vector<Index> allCells;
    allCells.reserve(currentDoc().cells_.size());

    for (auto it : currentDoc().cells_)
      allCells.push_back(it.first);

    std::stable_sort(allCells.begin(), allCells.end(), [](Index const& lhs, Index const& rhs) -> bool { return lhs.y < rhs.y; });
    std::stable_sort(allCells.begin(), allCells.end(), [](Index const& lhs, Index const& rhs) -> bool { return lhs.x < rhs.x; });

    // Collect and sort all columns so they are saved in the same order
    std::vector<int> allColumns;
    allColumns.reserve(currentDoc().columnWidth_.size());
    for (auto it : currentDoc().columnWidth_)
      allColumns.push_back(it.first);

    std::stable_sort(allColumns.begin(), allColumns.end());


    // Write file header
    file << "ZUM1" << std::endl;

    // Write column information section
    file << std::endl << "[columns]" << std::endl;
    for (auto col : allColumns)
      file << Index::columnToStr(col) << " = " << currentDoc().columnWidth_[col] << std::endl;
    
    // Write cell content
    file << std::endl << "[data]" << std::endl;
    for (auto idx: allCells)
    {
      const std::string text = getText(getCell(idx));

      if (!text.empty())
        file << idx.toStr() << " = " << text << std::endl;
    }

    // Write cell format
    file << std::endl << "[format]" << std::endl;
    for (auto idx: allCells)
    { 
      const Cell & cell = getCell(idx);

      if (cell.format != 0)
        file << idx.toStr() << " = " << formatToStr(cell.format) << std::endl;
    }

    file << std::endl;

    currentDoc().filename_ = filename;
    return true;
  }