I am trying to refresh my PivotTable which has been already rendered. Below is the code to refresh :
Excel.PivotTables pivotTables = worksheet.PivotTables();
Excel.PivotTable pvt = pivotTables.Cast<Excel.PivotTable>().FirstOrDefault(c => c.Name == pivotTableName);
pvt.RefreshTable(); //throws exception
I am getting below exception:
This command requires at least two rows of source data. You cannot use the command on a selection in only one row. Try the following:
• If you're using an advanced filter, select a range of cells that contains at least two rows of data. Then click the Advanced Filter command again.
• If you're creating a PivotTable report or PivotChart report, type a cell reference or select a range that includes at least two rows of data.
I am able to understand that the sourcedata gets corrupted or modified, but not able to reach the solution.
Any help or suggestion would be great.
Thanks.
Related
In this system one program creates table records and a second updates them. I want the update program to see the new records. See lots of queries/responses to this but so far none have worked for me. One solution was to clear and reload the dataset table. The following code recreates the dataset but I can't include the auto incremented primary key bookid. If it is there I get an overload error even thought the field count is correct. If I remove it the dataset.booking table is loaded but the bookid values are wrong negative numbers) and I can't update the dataset.booking table as it does not match the database table.
tclDataSet3.booking.AcceptChanges();
tclDataSet3.booking.Clear();
bookingBindingSource.ResetBindings(false);
dataGridView1.ClearSelection();
var bkas1 = tcdb.bookings.Where(b => b.approvalStatus == 1);
foreach (booking bk in bkas1)
tclDataSet3.booking.AddbookingRow(
(int)bk.bookId,
(int)bk.bookYear,
(int)bk.bookMonth,
(int)bk.bookDay,
(int)bk.workOrder,
(int)bk.customerNum,
bk.firstName,
bk.lastName,
bk.vehicle,
(int)bk.serviceCar,
bk.repairType,
(bool)bk.isCompleted,
(bool)bk.isPickedUp,
bk.outYear,
bk.outMonth,
bk.outDay,
(bool)bk.isDeleted,
(int)bk.isUpdated,
bk.bookingTime,
(int)bk.approvalStatus);
Program requirements:
display datagridview of dataset.booking table where as_code = 1
updates rows in datagrideview to change as_code = 2
remove updated rows from datagridview (bookingBindingSource.RemoveCurrent(); works well)
Refresh datagridview to see all dataset.booking table rows where as_code = 1
Currently the refresh only sees existing records in the datagrideview.
Is there a better way to do this?
After much trial and error I decided to rewrite the code to manually build the dataGridView rather than use any data binding. I created a subroutine to clear the dataGridView, read the base table and rebuild the dataGridView.
i have a small winforms application im working on and using ClosedXML to handle our excel files. Im trying to build the read logic in a way that no matter what row the headers are on, i can find that row and work with the data below that. Because our reports come from our enterprise reporting system, the files are not always the same in where they start with the data because the exports from our system appends the report filters and selections to the top x rows then below that it starts the data dump. So right now that only way i can get it to work is if i manually remove all those rows at the top and make the header row the first row.
Im looking for some assistance in how i can find the "header" row based on column names or any other method. I have already looked thru their wiki https://github.com/ClosedXML/ClosedXML/wiki but that only has mention of working with printing headers and footers..
Here is where i believe i need to focus my work, but unclear where to start:
// Look for the first row used
var firstRowUsed = ws.FirstRowUsed(); //{'Precision Calculator D'!A1:XFD1}
//var firstRowUsed = "'Precision Calculator D'!A9:XFD9";
// Narrow down the row so that it only includes the used part
var udasRow = firstRowUsed.RowUsed(); //{'Precision Calculator D'!A10:A10}
//var udasRow = "'Precision Calculator D'!A10:A10}";
// Move to the next row (it now has the titles)
udasRow = udasRow.RowBelow();
There are reports ive tried that have the header starting on row 5 and others that start on row 7 and so on, so there is no actual row that they will alays be on, so need to find a way to determine it automatically. is there anyway to determine the row that the column names are in? The columns will always be in the same order, so those i have determined.
So ran across this in a mention of closedXML and it def may help get me where i need to be, but unclear how to implement
var foundMonth = ws.Search("Month", System.Globalization.CompareOptions.OrdinalIgnoreCase);
Since it returns a IEnumerable there is a chance that there may be more than one cell with the value "Month" and in my file that im testing with, there is 2 rows that contain the word and not sure how i can determine in this case that i want the last cell it found if there are multiple.
Addressed the concern about the multiple cells returned, and can now determine which row the headers are on with the following:
var foundMonth = ws.Search("Month", System.Globalization.CompareOptions.OrdinalIgnoreCase);
var monthRow = foundMonth.Last().Address.ToString();
Still unclear how to implement this into the original code post above, so that the firstRowUsed is reflected correctly in this case would be A11:XFD11
After exhausting search of ClosedXML and reading thru a number of other questions, i was able to find a solution. Below is the code that will help set the used range based on my current data structure within the file..
var foundMonth = ws.Search("Month", System.Globalization.CompareOptions.OrdinalIgnoreCase);
var monthRow = foundMonth.Last().Address; // A11
var lastcell = ws.LastCellUsed().Address; // BC3950
var rangeUsed = ws.Range(monthRow, lastcell);
Since i have no idea where my header row will be from file to file, im searching for my column header name in column A, since all the usable data is mostly numbers i can safely assume that in column A, the last found instance of the word "Month" is my header row.
With that and the last cell used i am able to determine my data range as seen above. Although i still need to figure out how to replace my firstRowUsed logic to work the same way, this is a step closer to a final solution. Ill post back my findings on that one before i mark this question answered.
var firstRowUsed = ws.Range(monthRow, lastcell).FirstRowUsed();
This line provides you the same as this line below
var firstRowUsed = ws.FirstRowUsed();
I tried this logic with 3 different files, each one having more and less data and also having the header row on different rows. and works like a charm
I'm trying to import datatable with 1000000 records into Excel using EPPlus library.
ExcelWorksheet ws = pck.Workbook.Worksheets.Add("Demo");
var recordCount = dt.Rows.Count;
ws.Cells["A5"].LoadFromDataTable(dt, true);
I'm getting Row Out of Range exception on ws.Cells["A5"].LoadFromDataTable(dt, true); line
It worked when I had 1000 records.
Is there row limit size when working with EPPlus?
You probably tried to import a little bit more than 1.000.000 records. The maximum before throwing this exception is 1.048.576 (which exactly equals the maximum number of rows specified for Excel version 2010).
Have a look at the source code:
The last line of the LoadFromDataTable method in ExcelRangeBase.cs returns the imported excelrange: _worksheet.Cells[...]
You can find the implementation of this indexer in ExcelRange.cs and there you'll see that the range is validated by ValidateRowCol (all the way at the bottom).
Finally, this validation throws the exception you mentioned when the requested row is larger than the MaxRows property of an excelpackage, which equals 1.048.576
When you get "Row out of range", the row parameter is probably too high or too low.
Remember that it starts to count from 1.
I got this error when I had placed a list in a list. Should have been only a list and not a list in a list.
To be exact i created a list of object that I then placed in a list, parsed to JSON and loaded to a DataTable with JsonConvert.DeserializeObject(json, jsonFormat). Then I got the error.
I have a section in a Crystal Report that I want to suppress. I need to suppress it if there are 0 rows in a particular table in the dataset I am using. How would I do this? The Record Number special field provided appears to be an internal count of records in the report, and does not relate to the rows in the underlying data table.
I am creating the report from C#, but I cannot suppress the section from the code (it doesn't fit the project structure) - I must be able to do it from the report itself. The table concerned is definitely being passed to the report in the dataset, but it contains 0 rows. There must be a way to establish this inside the report itself.....
Can anyone please point me in the right direction?
In the Crystal Reports designer, view the properties of your section and there should be an option to Suppress, which you can give it a formula to return the appropriate boolean value.
You could then use the Count() function within that formula and (I believe) you can pass the name of your dataset to the Count() function to get the number of rows in that dataset.
I did the same thing on a complex report about 3 months ago but I don't have access to the report any more having changed jobs so I'm sorry I cannot be more specific, but hoepfully this gives you a starting point.
Just had a quick Google - try this.
If the section does only contain database fields and f.e. no text fields, then you could use the setting "Suppress Blank Section" in the "Section Export" (rightclick section) for that section.
As an alternative you could use the following formula in the "Suppress" in the "Section Export" for that section:
IsNull({table.field})
"{table.field}" is one of the fields in the dataset.
Hope this helps.
Go to "Section Expert" and click "Supress (No Drill-Down)" and try adding this:
IF {"DragYourFieldHere"} = "" then true else false
Create one dummy group,check on its header for each page,add the header in the group header of the dummy group.
I'm currently working on a legacy project that has some SQL needs to run to get some data.
They use DataTables, DataSets, etc to work with the data.
The query in question that gets executed only returns one row, however it contains well over 700 columns.
Unfortunately when the code executes to fill the data set, if the query contains over 655 columns, nothing gets returned.
Is there a way to get around this limitation so if a query returns 656+ columns data will get returned or is there some other workaround?
Thanks!
EDIT:
Chasing a red herring. The data is there, I just can't view it in the debugger as a table if there's 656+ columns in the data. The viewer can't handle more than 655.
The data is there, I just can't view it in the debugger as a table if there's 656+ columns in the data. The viewer can't handle more than 655.
Not sure if it resolve the issue but try using the overloaded Fill method
DbDataAdapter.Fill(Int32, Int32, DataTable[]).
As per MSDN document:
Adds or refreshes rows in a DataTable to match those in the data
source starting at the specified record and retrieving up to the
specified maximum number of records
See here for more http://msdn.microsoft.com/en-us/library/0z5wy74x%28v=vs.110%29.aspx