I have an Excel file with attached xml schema and cells mapped to the schema. Is it possible to import/export xml data in such excel using Aspose ? I can do it in Excel from Developer tab using Import/Export buttons, but I want to do it programmatically, without starting Excel.
Is this feature available at this time? We are considering using Aspose.Cells, but importing from XML is a key feature. We are currently serializing C# structures to XML and then importing them with Excel COM Interop, but we would like to use a solution that doesn't require running Excel on the server.
I have downloaded the trial version of Aspose.Cells for .NET v7.3.0 to check out this feature "40448 - Support XML Maps".
It does able to retrieve XmlMap object from the excel sheet, but not much info available in this object. If I want to export excel data to xml, does Aspose XML Maps has such functionality? So far I don't see we can do that. Please advise if there is such feature available in Aspose product.
As one of the user mentioned before, we can do it in Excel from Developer tab using Import/Export button. Currently in our project, we have used Excel Interop XmlMap to programmatically export excel data to xml based on user define xml map. However, Excel Interop is not a server side solution and it requires Excel client to install on server. Plus, Microsoft not recommend office automation on server side. That's why I'm looking for an alternate better solution. Please respond if Aspose product has such functionality.
I try your sample code and it can generate xml file for the cells you specified. Couple things I would like to check with you.
The ExportDataTable feature doesn't use the user defined XML map in the excel file. We still need to find out the worksheet, first row, first column, total row, total column. Unlike Excel Interop, once we know the XmlMap, we know the cell ranges it map to. We don't need to know the worksheet and find out first row, first column, total row, total column. Is there other similar methods in Aspose can do the similar thing?
When the cell has empty value, the xml tag for that field is skipped. If a cell on row 1 column 2 has no value but row 2 column 2 has value, then number of xml elements for row 1 and row 2 will be different. Is there any parameter we can set to not skip the column even if it has no value? We need the exported xml file to be in this way so that we can do the schema validation against XSD latter on. Currently Excel Interop has this functionality. If Aspose already have this feature, then we don't need to do extra data processing.
Do you have any sample code on how to use Aspose.Cells.XmlMap? Can you describe a bit more about this update "40448 - Support XML Maps"? What functionality XmlMap has?
Thanks Shakeel for your response. It will be useful if these features can be incorported with Aspose Cell product.
One more question related to this is GetRangeByName method. I want to ExportDataTable with the predefined range specified in excel instead of specifying first row, first column info in the code.
Specifically, I'm trying to using this method to get a name range that already defined in Excel template's Name Manager with below line of code:
Range MyRange = workbook.Worksheets.GetRangeByName("TestRange");
It doesn't work for me. MyRange will is null even my predefined range in Excel is correct.
If I create range at run time with a name then GetRangeByName, it can return the range.
Range range = worksheet.Cells.CreateRange("B6", "M10"); range.Name = "TestRange"; Range MyRange = workbook.Worksheets.GetRangeByName("TestRange");
My question is do we have to create range at run time in order to GenRangeByName? Does GetRangeByName method able to get the range that already defined in Excel? If yes, please let me know how.
It looks like your above code sample or workbook.Worksheets.GetRangeByName("TestRange") will work if the name range is static. If the name range is dynamic, then it doesn't work for both methods.
Here is what I mean dynamic name range. In excel file, I have Xml Map imported. When I map the data in excel sheet, it creates table range under Formulas -> name manager. When user continue insert data in the mapped table, the name range change dynamically.
Please see attached sample excel file and screen shot for the dynamic name range and static name range. Your sample code or workbook.Worksheets.GetRangeByName("StaticRange") works for the static range. But fail with Dynamic range like workbook.Worksheets.GetRangeByName("BookTableRange"). Let me know if you can get the dynamic range work.