I am trying to remove the range through aspose but no luck. Actually i have created a range in excel but while exporting the excel when there is no data to insert into the excel and when we select the range it always select the empty rows. So i want to update the range to the header only or first delete the range and then again adding that.
Please suggest?
Thanks in advance.
You may use any of the NameCollection.Remove or RemoveAt methods to remove a particular Named Range from the collection. Please review the following piece of code as well as the details article on Named Ranges in prespective of Aspose.Cells for .NET APIs.
var book = new Workbook(dir + "book1.xlsx");
var names = book.Worksheets.Names;
names.Remove("range");
In case you still face any difficulty, please share your sample spreadsheet in Aspose.Cells support forum.
Note: I work with Aspose as Developer Evangelist.
Related
i have a spreadsheet with table generated with SpreadsheetLight library, and chart from this table also generated with SpreadsheetLight. When i open generated result in excel and select chart, i can change rows for cols with button in excel (i don't have excel in english language so i'm just guessing it is called "change rows and cols"). Is there posibility to do this by code with SpreadsheetLight while generating spreadsheet? Or is it possible to tell SpreadsheetLight which data should be on category and which on data axis?
Thank you for any help.
So the answer for my own question is, that there is an overload of method SLDocument.CreateChart(), where is parameter RowsAsDataSeries. Or there is also an overload with SLCreateChartOptions parameter, and inside of SLCreateChartOptions is property RowsAsDataSeries. Second option seems to be better because the first one is marked as obsolette.
Many thank's to Mr. Vincent Tan for help and for great OpenXml library :)
I am struggling with the Open XML SDK and I've already read a lot of posts on this topic but cannot figure it out. My goal is to have a locally created Excel file which contains a formula and edit the input online and retrieve the calculated value online.
I don't know if this is possible since Open XML may only change the data and I wonder if it is also able to perform Excels calculations.
For example, my local file contains three cells:
A1: 1
A2: 2
A3: =(A1+A2)
Using Open XML I adjust A2 to the value of 3, however the result of A3 remains 3 instead of 4.
I have already read about Excel having to recalculate, but my goal is to have an Excel file as some sort of calculation engine instead of transfering all calculations to C#.
All tips and advice are welcome.
Kind regards, Patrick
First of all thanks for all responses.
Second I guess the response answered my question and the open XML SDK is only able to adjust the file and won't do anything regarding recaculating existing formulas in the file. This will only occur when opened in Excel. I will take a look at EPPlus.
You can use something like this.
Cell cell; //supposing this is your cell referencing A3
CellFormula cellformula = new CellFormula();
cellformula.Text = "SUM(A1, A2)";
CellValue cellValue = new CellValue();
cellValue.Text = "0";
cell.Append(cellformula);
cell.Append(cellValue);
A similar example can be found at this link: Formula cells in excel using openXML
I feel there could be some ambiguity captured in the question. OpenXML is way of storing documents, therefore it is not possible to do calculations with OpenXML SDK. It is spread sheet engine (Excel application) which performs the calculations.
When inputs are updated, spreadsheet saved, calculated values should get updated.
I'm developing a MVC 4 web application and one of the requirements is to allow users to upload an excel file which is in a standard format and extract data and save that to a database. I have used linq to excel to read data off of the excel. This works fine provided that the table that I'm extracting data from starts from the first row of the excel sheet.
var details = from c in excel.Worksheet<ContributionScheduleExcelFormat>() select c;
Now my question is how can we still return the same data if say the table headers starts on the third row? Basically some extra information needs to be reflected on the first two rows so that's why my the table in the excel sheet needs to start from the third row now. I believe there is a function already available to get data from a range of cells.
var details = from c in excel.WorksheetRange<ContributionScheduleExcelFormat>(startRange, endRange) select c;
But how would I get the endRange value?
I'm new to linq to excel so please any assistance would be greatly appreciated. Thanks in advance.
For the sake of others that may have this same issue:
Turns out that you can't actually do this at the moment. The only solution is to specify an end range that you know your excel sheet data will not exceed. For example:
var details = from c in excel.WorksheetRange<ContributionScheduleExcelFormat>("A3", "G16000") select c;
It's not pretty at all and personally just looking at it makes me feel uncomfortable but that's the only way right now.
I am making an add-in and I am trying to format the output which my add-in generates,using Format as table table-styles provided by Excel.
The one which you get on the 'home tab' --> 'Format as Table' button on the ribbon.
I am using following code:
SourceRange.Worksheet.ListObjects.Add(XlListObjectSourceType.xlSrcRange,
SourceRange, System.Type.Missing, xlYesNo, System.Type.Missing).Name =
TableName;
SourceRange.Select();
SourceRange.Worksheet.ListObjects[TableName].TableStyle = TableStyleName;
TableStyleName is any style name like TableStyleMedium17, you get it if you just hover a particular style in Excel.
My problem is that, even if I keep the SourceRange as 10 columns, all the columns right till the end get selected and are considered as one table.
Because of that the table I populate right next to it is also considered as a part of the first table that was generated.Since, both the table have same column names excel automatically changes the column names in all the following tables that are generated.
Also, because I am generating the tables in a loop after 2 tables are generated I get the error :
A table cannot overlap another table.
PS: I am clearly mentioning SourceRange as:
var startCell = (Range)worksheet.Cells[startRow, startCol];
var endCell = (Range)worksheet.Cells[endRow, endCol];
var SourceRange = worksheet.get_Range(startCell, endCell);
Kindly suggest a way out.
We were able to figure out what was happening on our end for this:
on the
xlWorkbook.Worksheets.Add([before],[after], Type.Missing, Type.Missing)
call, we had to flip before and after since we wanted the sheets to move right, not left and then accessed
xlWorkbook.Worksheets[sheetCount]
by increasing sheetcount for however many sheets were being generated.
Having it the other way was creating the worksheet to access a previously assigned table formatfrom the SourceRange.Worksheet.ListObjects[TableName].TableStyle = TableStyleName call.
So, I got around this problem a week after posting this, sorry did not update in the rush of things.
This actually is an in built excel functionality.
You cant help it, the excel application will keep doing this.
So, ultimately wrote my own table styles in c# and applied it to the excel range which is mentioned as SourceRange. Its just like writing CSS.
If you are interested in knowing the details of that comment it on this question itself or you can contact me by email from my profile.
I have an excel sheet and I am processing it by using Open XML SDK 2.0. The scenario is, There is a column which contains date in my excel sheet. I need to get the maximum and minimum date from that column.
I can do this by looping and reaching to that cell, doing comparisons and finding desired answer.
But due to optimality I want to do this by using LINQ to get Minimum and maximum dates.
Is it possible to do so? If yes, then how?
You can see how to get IEnumerable of all cells from column there:Read excel sheet data in columns using OpenXML, and use Max() on it.
Thanks to all
I have used like this
IEnumerable<Cell> cells = workSheetPart.Worksheet.Descendants<Cell>().Where(c => string.Compare(GetColumnName(c.CellReference.Value), strIndex, false) == 0).OrderBy(c => c.CellValue.Text);
And getting min and max values like this
int cellCount = cells.Count();
Cell MaxCell = cells.ToArray()[0];
Cell MinCell = cells.ToArray()[cellCount - 1];
You will want to take a look at the LINQ Min() and Max() functions. If you need to return the entire Cell object, you can use OrderByDescending().
You could read this post Open XML SDK and LINQ to XML by Eric White (Eric wrote a lot of posts about OpenXML and LINQ). And then you will be able to query your Excel file data with LINQ. You might want to see the spreadsheet objects structure in The Open XML SDK Productivity Tool, which can generate the source code for you. You could use this code to understand how to programmatically access the data you need.