C# SpreadSheetsLight axis - c#

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 :)

Related

Is Open XML SDK 2.5 able to recalculate Excel formulas?

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.

How to delete Range in Aspose(using C#)

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.

Using LINQ with Open XML (Excel)

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.

ASPOSE.Cell -How to read the calculated value from a AddIn Formula Cell

I am using ASPOSE.Cell Component to read an Excel.
I am able to read normal values from cells. But in my excel few cell values are driven by Add-In formulas, which i am not able to read. When i read the value of those cells using cell[].Value, i am always getting NULL.
Has anyone experienced this?
Please advice.
Thanks
K B B
Status update:
We are working on this issue with ASPOSE support team, you can follow it on
http://www.aspose.com/community/forums/349499/aspose.cell-to-read-the-calculated-values-using-addin-formulas/showthread.aspx#349499

Output table from excel using xslt

I would like to output a table to a webpage. The table is stored in an excel sheet (xls).
Is it possible to use xslt for this? The table is the cells are in this range:
A26 - P36 (16 columns and 11 rows)
If an exmaple file is need here is a link:
http://finans.opengate.dk/media/6704/2010-01-13.xls
Update: A daily file is uploaded. And I would like to automatically show a table from the latest xls-file using xslt. If some C# is needed to convert it from excel to something else (XML?) that is fine. It is done in the CMS Umbraco and that is why I hope to use XSLT since that is the way to show things in Umbraco, through xslt makroes.
BR. Anders
UPDATE with answer (based on answers below): No, it is not possible to read xls-files using xslt. If needed then one has to save excel sheet in another format xml or html. Or one will need a real programming language to read the excel file.
XSLT is mostly used to convert XML from one dialect to another, not to convert xls files to html.
If you just want to do this manually, you can save your worksheet as HTML directly in excel.
It is not clear from your question if you want to do this programmatically, and if so using what programming language.
You can use ADO.net to access cells in an excel file, similar to a DB query. This is a bit lighter than trying to use Excel automation objects.
http://support.microsoft.com/kb/316934
SpreadsheetGear for .NET can read Excel files and display them in a DataGrid as shown in the Excel to DataGrid sample on this page:
// Create a workbook from an Excel file
String ssFile = Server.MapPath("files/spiceorder.xls");
SpreadsheetGear.IWorkbook workbook = SpreadsheetGear.Factory.GetWorkbook(ssFile);
// Get a DataSet from an existing defined name
DataSet dataSet = workbook.GetDataSet("orderrange", SpreadsheetGear.Data.GetDataFlags.FormattedText);
// Bind a DataGrid to the DataSet
DataGrid1.DataSource = dataSet;
DataGrid1.DataBind();
SpreadsheetGear can also render png/gif/jpg images from cell ranges or charts as demonstrated here.
You can download the free trial here if you want to try it yourself.
Disclaimer: I own SpreadsheetGear LLC

Categories

Resources