I have got a chart and the data has been inserted so I have to extend the range of source data.
The original format
line chart
I am just writing like this
sheet.ChartObjects(0).SetSourceData(sheet.get_Range("B2", columnA + 5),Excel.XlRowCol.xlColumns);
and the program shutdown at this and log reads "System.Runtime.InteropServices.COMException"
"HRESULT:0x800A03EC"
I don't know the error and I didn't know how to show the previous source data range and format.If I can get the original source range with right format,I may modify parameter appropriately.
PS:I have found something here setsourcedata-correct-call-parametersbut I couldn't correct my code......
Related
I'm reading an .xlsx spreadsheet into a C# console app with a view to outputting the content as a formatted xml file (to be picked up by another part of the system further down the line).
The problem with the the .xslx file is that it's a pro-forma input document based on, and replacing, an old paper-based order form we used to provide to customers, and the input fields aren't organised as a series of similar rows (except in the lower part of the document which consists of up to 99 rows of order detail lines). Some of the rows in the header part of the form/sheet are a mixture of label text AND data; same with the columns.
Effectively, what I need to do is to be able to cherry pick data from the initial dozen or so rows in order to poke data into the xml structure; the latter part of the document I can process by iterating over the rows for the order detail lines.
I can't use Interop as this will end up as an Azure function - so I've used ExcelDataReader to convert the spreadsheet to a dataset, then convert that dataset to a new dataset entirely composed of string values. But I haven't been able to successfully point to individual cells as I had expected to be using syntax something like
var cellValue = MyDataSet.Cell[10, 2];
I'd be grateful for any advice as to how I might get the result I need.
A Dataset has Tables and those have Rows which hold ColumnValues
A WorkSheet transforms into a Table (with Columns) and the Cells transform to Rows and column values.
To find the cell value at [10,2] on the first Worksheet do:
var cellValue = MyDataSet.Tables[0].Rows[10][2];
Remember that cellValue will be of type object. Cast accordingly.
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.
I am using Gembox-spreadsheet to parse excel files with multiple sheets.
I am currently loading a file using the following code:
excelFile.LoadXlsx(inputExcel, XlsxOptions.None);
where inputExcel is a fullpath. After importing the excel, I try to access its content (for each sheet, parse rows and obtain cell data). The problem here is that after loading the document, in debug mode if I check the values in a sheet, I see this error:
'excelFile.Worksheets.ActiveWorksheet.Cells.Value' threw an exception of type 'System.InvalidOperationException'.
However, when I try to retrieve the information from a cell (which contains some info, doesn't matter of which type) it retrieves 0.
Does anybody know why this error occurs and how I can prevent it?
I must mention that the values in the cells are generated through formulas, from a separate worksheet. Could this be why the values are not loaded?
Well, I found the problem. Because the cell values are obtained through formulas, when loading the file you must set XlsxOptions.PreserveWorksheetRecords (for xls) or XlsOptions.PreserveKeepOpen (for xlsx)
I am writing a C# application that reads data from an Excel file. Everything was running smoothly until I attempted to read from a cell that used a formula.
I am pulling data from the sheet and trying to add the cumulative quantity, so in a loop, I'm using:
cntr = Cell(row, column);
NOTE: I'm paraphrasing rather than copy my actual code.
Anyways, if the actual cell value contains a number, this works, but if the cell contains a function, it returns the string
"=SUM(A1:A5)"
and I'm not sure how I can execute this in my C# code to retrieve the actual value of that cell.
Try
Cell(a,b).Value
instead of just Cell(a,b).
Also, the following approach should work
Excel.Range objRange = (Excel.Range)objSheet.Cells[rowN,colN];
variableName = objRange.get_Value(System.Missing.Type).ToString();
You may modify it for your datatype
I'm trying to get my program to dump out data into an Excel spreadsheet. At the moment, it simply puts the information into the proper cell calculating any calculated values as needed within my code. What I would really like to do is instead of writing out the calculated values is to write out the Excel formulas to the cells that contain calculated values. That way, if I give the Excel document to someone, they can change the data in it and the calculated values will update as expected.
The problem is that I don't know how to get the "A1" style coordinates which Excel would expect. Basically, I'm hoping that there's something like this available:
calculatedCell.Value = string.Format("=SUM({0})", range.Coordinates);
I know I can get the row and column index for the range, and using those I could evaluate the coordinates myself, I was just hoping there was a pre-packaged way of doing it.
There should be an Address property on Range.
Try this:
calculatedCell.Value = string.Format("=SUM({0})", range.get_Address(true, true,
XlReferenceStyle.xlA1,
false, null));