Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
justkawal committed May 15, 2020
1 parent 5049053 commit 4bb07cd
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 14 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@
All notable changes to this project will be documented in this file.

## [Future Updates coming soon]
- Find and Replace
- Add row / column from Iterables
- Formulas
- Font Family
- Text Size
- Italic
- Underline
- Bold

## [1.0.6] - 2020-05-16
### Added Functionality
- Find and Replace
- Add row / column from Iterables

## [1.0.5] - 2020-05-15
### Removed
- Bugs related to Spanning
Expand Down
4 changes: 3 additions & 1 deletion example/excel_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ void main(List<String> args) {
// excel.insertRow(sheet, 2);

excel.appendRow(sheet, ["bustin", "jiebr"]);
excel.findAndReplace(sheet, 'bustin', 'raman');

int replacedCount = excel.findAndReplace(sheet, 'bustin', 'raman');
print("Replaced Count:" + replacedCount.toString());

excel.setDefaultSheet(sheet).then((isSet) {
// isSet is bool which tells that whether the setting of default sheet is successful or not.
Expand Down
44 changes: 33 additions & 11 deletions lib/src/excel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1094,28 +1094,50 @@ abstract class Excel {
}
}

/// append row
appendRow(String sheetName, List<dynamic> data) {
/// Append [row]
appendRow(String sheetName, List<dynamic> row) {
int targetRow = _tables[sheetName].maxRows;
insertRowIterables(sheetName, row, targetRow);
}

insertRowIterables(String sheetName, List<dynamic> row, int rowIndex,
{CellIndex startingColumn}) {
if (row == null || rowIndex == null) {
return;
}
_checkSheetArguments(sheetName);
var targetRow = _tables[sheetName].maxRows;
data.asMap().forEach((index, value) => updateCell(
_checkSheetMaxRow(sheetName, rowIndex);
int columnIndex = 0;
if (startingColumn != null) {
columnIndex = startingColumn.columnIndex;
}
_checkSheetMaxCol(sheetName, columnIndex + row.length);
row.asMap().forEach((index, value) => updateCell(
sheetName,
CellIndex.indexByColumnRow(columnIndex: index, rowIndex: targetRow),
CellIndex.indexByColumnRow(columnIndex: index, rowIndex: rowIndex),
value));
}

/// find and replace
int findAndReplace(String sheetName, dynamic source, String target) {
/// Replace the [source] with [target]
///
/// Here [source] can also be a user's custom [RegExp]
///
/// optional argument [first] can be used to replace count of source occuring first
///
/// If [first] is set to [3] then it will replace only first 3 occurences of the source
int findAndReplace(String sheetName, dynamic source, String target,
{int first = -1}) {
_checkSheetArguments(sheetName);
var replaceCount = 0;
var rowIndex = 0;
int replaceCount = 0, rowIndex = 0;
for (var row in _tables[sheetName].rows) {
var sourceRegx = RegExp(source.toString());
RegExp sourceRegx = RegExp(source.toString());
if (source.runtimeType == RegExp) {
sourceRegx == source;
}
row.asMap().forEach((columnIndex, value) {
if (value != null && sourceRegx.hasMatch(value)) {
if (value != null &&
sourceRegx.hasMatch(value) &&
(first == -1 || first != replaceCount)) {
updateCell(
sheetName,
CellIndex.indexByColumnRow(
Expand Down

0 comments on commit 4bb07cd

Please sign in to comment.