CleanExcelNewlines Activity

Purpose: This activity removes newlines and carriage returns from all cells in an Excel file. This is useful for cleaning data exported from SolidWorks or other systems that may contain unwanted line breaks in cells. The activity processes the specified worksheet and removes newline characters (\n) and carriage returns (\r) from all cell values.

Input Properties

FilePath

The full path to the Excel file to process. This must be an existing Excel file that is accessible and writable.

Type: string

Required: Yes

Example: "C:\Data\Workbook.xlsx"

SheetName

The name of the worksheet to process. If empty or not specified, defaults to the first sheet in the workbook.

Type: string?

Required: No

Example: "Sheet1" or "Data" or leave empty for first sheet

Note: If not specified, the first sheet in the workbook will be processed.

Output Properties

Success

True if the file was processed successfully, false otherwise.

Type: bool

Note: Returns false if the FilePath is null or empty, if the file does not exist, if the sheet is not found, if the file cannot be modified, or if an error occurs.

ErrorMessage

Error message if processing failed. Empty string if processing succeeded.

Type: string

Note: Contains an error message if Success is false. Error messages may include: "File path is required.", "Failed to process Excel file.", or "Error processing Excel file: {exception message}".

CellsModified

Number of cells that were modified during processing.

Type: int

Note: Returns the count of cells that contained newlines and were cleaned. Returns -1 if processing succeeded but the exact count is not available. Returns 0 if processing failed or if no cells were modified.

Usage Example

Scenario: Clean newlines from an Excel file

Configuration:
- FilePath: "C:\Data\Workbook.xlsx"
- SheetName: "Sheet1"

Result:
- Success: true
- ErrorMessage: "" (empty string)
- CellsModified: 15 (15 cells had newlines removed)

Scenario: Clean newlines from first sheet (default)

Configuration:
- FilePath: "C:\Data\Workbook.xlsx"
- SheetName: "" (empty, uses first sheet)

Result:
- Success: true
- ErrorMessage: "" (empty string)
- CellsModified: 8

Error Handling

Important: The activity handles errors gracefully:

  • If FilePath is null or empty, Success will be false, ErrorMessage will contain: "File path is required.", and CellsModified will be 0
  • If the file does not exist or cannot be accessed, Success will be false, ErrorMessage will contain: "Failed to process Excel file.", and CellsModified will be 0
  • If any exception occurs, Success will be false, ErrorMessage will contain: "Error processing Excel file: {exception message}", and CellsModified will be 0
  • The activity does not throw exceptions - errors are indicated by the Success output and ErrorMessage

Always check the Success output and review the ErrorMessage if processing fails. The CellsModified count indicates how many cells were cleaned.

Important Notes

  • The FilePath must point to an existing Excel file that is accessible and writable
  • The file must not be locked by another process (e.g., open in Excel)
  • This activity modifies the file by removing newlines and carriage returns from cell values
  • If SheetName is not specified, the first sheet in the workbook will be processed
  • Only cells containing newlines (\n) or carriage returns (\r) will be modified
  • Consider backing up important files before cleaning, as the changes are permanent
  • This is particularly useful for cleaning data exported from SolidWorks that may contain unwanted line breaks

Related Activities