Home Documentation Writing Reading Pictures1 Pictures2 Formulas DateTime SheetByName
Merging Grouping InsertRowCol NumFormats Formats Fonts Buffer1 Buffer2 Copying TopNFilter
Sorting StringFilter NumberFilter FilterByValues Protection Replacing RichString BeginWith
ColorScale OpRule AltRows
Merging Grouping InsertRowCol NumFormats Formats Fonts Buffer1 Buffer2 Copying TopNFilter
Sorting StringFilter NumberFilter FilterByValues Protection Replacing RichString BeginWith
ColorScale OpRule AltRows
Replacing the specified characters in all cells
This example shows how to replace "+-" characters with "±" in all cells and sheets:#include "libxl.h" #include <string> using namespace libxl; int main() { Book* book = xlCreateXMLBook(); bool b = book->load(L"in.xlsx"); for(int i = 0; i < book->sheetCount(); ++i) { Sheet* sheet = book->getSheet(i); for(int row = sheet->firstRow(); row < sheet->lastRow(); ++row) { for(int col = sheet->firstCol(); col < sheet->lastCol(); ++col) { if(sheet->cellType(row, col) == CELLTYPE_STRING) { const wchar_t* s = sheet->readStr(row, col); if(s) { std::wstring str(s); std::wstring::size_type pos = str.find(L"+-"); if(pos != std::wstring::npos) { str.replace(pos, 2, L"±"); } sheet->writeStr(row, col, str.c_str()); } } } } } book->save(L"out.xlsx"); book->release(); return 0; }