Hi @sob,
I restarted,but no luck:(
Hi @sob,
I restarted,but no luck:(
hi,
Sound like you are missing the nampace Microsoft.Office.Interop.Excel please import it in your file
yeah ,i did that aleady
Could you share your file
I too faced the same issue but after restarting my program ,the error goneâŚit is working fine
Updated Version
includes:-
1. Filtration of pivots and select and unselect
2. Hiding of Subtotal
3.Selection the pivot item
Dim s1 As Microsoft.Office.Interop.Excel.PivotItems=CType(oPivotField.PivotItems,Microsoft.Office.Interop.Excel.PivotItems)
System.Windows.MessageBox.Show(CType(s1(0),Microsoft.Office.Interop.Excel.PivotItem).Name)âReturns forst value of the filed 0 is the indexâ
For Each s As Microsoft.Office.Interop.Excel.PivotItem In CType(oPivotField.PivotItems,Microsoft.Office.Interop.Excel.PivotItems)âReturns the feild itemsâ
System.Windows.MessageBox.Show(s.Name)
''s.Visible=False âinSelect the check boxâ
Next
4.Enable multi Select
oPivotField.EnableMultiplePageItems=True âenable of mulitselectâ
5.Selection of single item
oPivotField.CurrentPage=âBasicsâ âSelect the Basic in filterâ
oPivotField.CurrentPage=âToysâ
pivot_table.zip (11.4 KB)
Copying of pivot table below the code
Dim excel As Microsoft.Office.Interop.Excel.Application
Dim wb As Microsoft.Office.Interop.Excel.Workbook
Dim ws As Microsoft.Office.Interop.Excel.Worksheet
Dim p_ws As Microsoft.Office.Interop.Excel.Worksheet
Dim rng As Microsoft.Office.Interop.Excel.Range âcapturing the range of sheet1 âââ
Dim p_rng As Microsoft.Office.Interop.Excel.Range âcapturing the range of pivottable shhet1ââ
Try
excel = New Microsoft.Office.Interop.Excel.ApplicationClassâcreate the instance of excel work bookâ
wb = excel.Workbooks.Open(âD:\Users\Default User\Documents\UiPath\copy of pivot tables\01-Stock at RNA.xlsxâ)âOpen the excel the fileâ
excel.Visible=True
ws=CType(wb.Sheets(âSummaryâ),Microsoft.Office.Interop.Excel.Worksheet)âselect a sheet and activiatesâ
ws.Activate
'Creation pivot Cache and pivot table â
Dim oPivotCache As Microsoft.Office.Interop.Excel.PivotCache=Nothing
Dim oPivotTables As Microsoft.Office.Interop.Excel.PivotTables=Nothing
Dim oPivotTable As Microsoft.Office.Interop.Excel.PivotTable=Nothing
oPivotTable=DirectCast(ws.PivotTables(âSummary_1â),Microsoft.Office.Interop.Excel.PivotTable)
oPivotTable.TableRange2.Copy
wb = excel.Workbooks.Open(âD:\Users\Default User\Documents\UiPath\copy of pivot tables\pivots.xlsxâ)âOpen the excel the fileâ
excel.Visible=True
p_ws=CType(wb.Sheets(âsheet1â),Microsoft.Office.Interop.Excel.Worksheet)âselect a sheet and activiatesâ
p_ws.Activate
''p_ws.Cells.PasteSpecial(XlPasteType.xlPasteValuesAndNumberFormats)
p_ws.Range(âA15â).PasteSpecial(XlPasteType.xlPasteValuesAndNumberFormats)
âSummary_1â
Catch es As Exception
System.Windows.MessageBox.Show(es.Message)
End Try
Regards
Sanjay Shankhla
Hi,
I used the code which you have shared and replaced with the fields from my excel file. But I am getting the error pop âThe pivot table field name is not validâ. Can you pleas help?
pivot_table.zip (27.5 KB)
Hi @kavyashreeh22,
Found the mistake
in sample file the headers starts at A1
and you have given from a2,x20 this is why you getting the error as field names are invalid
Plz Correct it and run again
Regards
Sanjay
Hi Sanjay,
Thanks so much, its working fine now.
Can you please tell me how we can assign a sheet name to the sheet where the pivot table is generated. It assigns as âSheet*â by default.
Also, how can we pass the arguments to the code? Like filepath, sheet name etc.
To add a new worksheet to the workbook use this code:
var xlSheets = xlWorkBook.Sheets as Excel.Sheets;
var xlNewSheet = (Excel.Worksheet)xlSheets.Add(xlSheets[1], Type.Missing, Type.Missing, Type.Missing);
xlNewSheet.Name = "newsheet";
// Uncomment a line below if you want the inserted sheet to be the last one
//xlWorkBook.Sheets.Move(After: xlWorkBook.Sheets.Count);
To save the workbook call Save()
method:
xlWorkBook.Save();
And yes you can pass an argument in the invok e code editor
Regards
Sanjay shankhla
Thanks, but my question is, this Pivot table will be generated in a separate new sheet and will be named Sheet1, Sheet2 etc. Is there any way we can specify the sheet name while generating the Pivot table?
Also, how can we read this pivot table using UiPath? Using excel read range, I am getting below error,
Hi @kavyashreeh22,
Naming of the sheet is possible using the worksheet.Name property for more details i have provided the details please check in the below link
coming to Read pivot Using i believe yes we can.just for the demo can attach some pivot file
Regards
Sanjay Shankhla
Attached sample pivot table in Sheet1.sample test data.xlsx (21.5 KB)
hi @kavyashreeh22,
please check you can read the pivot using read range
pivot_readfile.zip (20.4 KB)
regards
Sanjay
Hi Cheersrpa, @cheersrpa
Please add a new variable to the Workflow of the type (Microsoft.Office.Interop.Excel).
Save the file and run, it will work fine.
Regards,
Karthikeyan R
Hi Sanjay,
We are facing âwriting lock file to disk. path=âŚalldependencies.jsonâ error while doing it in new project.
hi, this is very useful
but how to select excel sheet with dynamic range?
Sanjay, thanks for the pivot xml vbcode, works very well. Though after the table is created, the workbook is read only and is not saved. I tried to modify with the code below to save and quit the workbook, but no luck. Please advise. thanks.
wb.SaveAs(âC:\test.xlsxâ)
wb.Close(savechanges:=True)
Hello @sanjay21051990
I can see that you have written Vb code , but can u pls help me out in reading range from excel which is dynamic (as my data keeps changing every week) also can you help me to write code for filters in pivot so that i get data only for particular filter.
Please find my sample sheet .Sample.xlsx (1.4 MB)