cancel
Showing results for 
Search instead for 
Did you mean: 

Trim all Cells in Excel before importing to a collection

RicardoCabrera
Level 3
Hello  My issue is related to Excel and SAP reporting, I need to download a report from SAP and then extract that report and put it in a collection, however, I've noticed that when I download the report, it can sometimes have additional spaces in the header names, when this happens I cannot reference the collection because now it has a different header name, i.e. [SAP Report.Value] [SAP Report.  Value]. What I'm trying to do is to trim all cells in the excel file before adding its contents to a collection, to do this, I'm trying to use a code stage with the following VB code: Dim worksheet As Object worksheet = GetWorkbook(handle,Nothing).ActiveSheet Dim cell as Object = worksheet.Range For Each cell In worksheet.UsedRange.SpecialCells(xlCellTypeConstants) cell = WorksheetFunction.Trim(cell) Next cell however I'm getting the following error xlCellTypeConstants is not declared, It may be inaccessible due to its protection level. this code works in excel but since I'm new to code stages in BP, any idea of why I'm getting this error or any suggestions to trim all content before importing to a colleciton? thanks in advance  
3 REPLIES 3

John__Carter
Staff
Staff
xlCellTypeConstants is part of a VBA enumeration, and you'll be able to replace it with a 2. See https://docs.microsoft.com/en-us/office/vba/api/excel.xlcelltype

AndreyKudinov
Level 10
I simply modified Collection manipulation action like this: For Each Column As DataColumn In Input_Collection.Columns    Column.ColumnName=Microsoft.Visualbasic.Replace(Column.ColumnName,""."","""").Trim() Next Output_Collection = Input_Collection

RicardoCabrera
Level 3
thanks, John didn't see your reply on time, I ended up doing something aikudino's suggestion although this only works for the headers it helped me to deploy a quick fix, I'll test replacing xlCellTypeConstants with a ""2"" and see if that solves the issue, that way I'll have two methods on how to trim cells from excel and within the BP collection thank you for helping me BR