okay, so here is the code I use-
var range = namedRange.GetRange();
if (range != null)
{
if (range.RowCount == 1 && range.ColumnCount == 1)
{
var cell = range[0, 0];
var value = cell.Value;
if (value != null)
{
return Encoding.UTF8.GetBytes(value.ToString());
}
return Array.Empty();
}
here is the sheet I want the values from-
type sheet.zip (6.5 KB)
Say I have a currency value $300 or a short date like 12-02-2021, and i get it using the above code. I want it to return $300 and 12-02-2021 which it is currently not. for any date it return dd-mm-yy hh-mm-ss, and currency is not being passed on.
@Adhirath
Cell.Value returns the original value of the cell, not the display value.
Please try Cell.StringValue or cell.GetStringValue() method
Workbook sourceWorkbook = new Workbook(dir + "type sheet.xlsx");
Cells cells = sourceWorkbook.Worksheets[0].Cells;
for(int i = 4; i < 9; i++)
{
Cell cell = cells[i,6];
Console.WriteLine(cell.StringValue + " : " + cell.GetStringValue(CellValueFormatStrategy.DisplayStyle));
}
That helps, facing an issue with currency. instead of rupee 300 I am getting this â¹ 300.00 when using the above code. What could be the issue?
It is happening because of the base64encoding i do after I get the value. It doesnt recognize the rupee symbol. Is there a fix for that?
nvm ,got it. Thank you soo much for the help!
@Adhirath
You are welcome. If you have any questions, please feel free to contact us at any time.
1 Like
The issues you have found earlier (filed as CELLSNET-57903,CELLSNET-57925) have been fixed in this update. This message was posted using Bugs notification tool by leoluo
1 Like
Hi I had another query, how do I do the same but for a chart. I am able to find the chart. Basically I want to save only the chart when doing doxcsave.
@Adhirath,
Similarly if you need to export the chart (only) in Excel spreadsheet, you may set printable area/range which should cover your desired chart area to be exported in the DOCX. To get the chart area range you may make use ChartObject’s specific attributes/properties. See the following sample code for your reference.
e.g.,
Sample code:
// Load the workbook containing the chart
Workbook workbook = new Workbook("e:\\test2\\Bk_chart1.xlsx");
Worksheet worksheet = workbook.Worksheets[0]; // Assuming chart is in the first worksheet
// Get the first chart in the worksheet
Chart chart = worksheet.Charts[0];
// Retrieve the chart's position and size
int startRow = chart.ChartObject.UpperLeftRow;
int startColumn = chart.ChartObject.UpperLeftColumn;
int endRow = chart.ChartObject.LowerRightRow;
int endColumn = chart.ChartObject.LowerRightColumn;
// Define the chart range as printable area
string printableArea = CellsHelper.CellIndexToName(startRow, startColumn) + ":" + CellsHelper.CellIndexToName(endRow, endColumn);
// Set the printable area for the worksheet
worksheet.PageSetup.PrintArea = printableArea;
DocxSaveOptions options = new DocxSaveOptions();
workbook.Save("e:\\test2\\out1.docx", options);
Hope, this helps a bit.
The chart name saved in excel and the one in aspose chart objects is different, Why?
@Adhirath,
Please zip and attach the Excel file and output DOCX file. Also, share your sample (runnable) code. We will check your issue soon.
Okay so I dont just want the image of the chart I want it’s OOXMl. how do i get that?
@Adhirath,
This is not supported as chart image would be rendered in the output DOCX. Maybe, embedding Excel chart as an OLE object in MS Word document can be an option. I think you may check with Aspose.Words team (in relevant forum) if they support it and how to accomplish the task.
@Adhirath
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): CELLSNET-52212 Support converting editable chart to docx
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.
1 Like
one more query, when I adjust imageOrPrintOptions why are the vertical and horizontal resolution metrics in dpi? from my understanding dpi should only affect print quality but it ends up improving my image quality if i keep it 150 or higher and i get worse quality at 96 or less. How does this work ?
@Adhirath,
The DPI (dots per inch) settings in ImageOrPrintOptions
directly affect the image (rendering) quality and not just printing quality. Please note:
- Higher DPI (e.g., 150–300 or more) results in clearer images with sharper text and graphical objects (e.g., charts).
- Lower DPI (e.g., 96 or less) can make images pixelated or blurry.
- Aspose.Cells treats DPI as a rendering resolution metric for bitmap conversion.
1 Like
Hi guys we are planning to buy the license for the latest version of Aspose. Just wanted to confirm if all the formatting will be transferred when I save a range as Docx such as the borders and intrinsic allignment, etc. Also wanted to know if the chart saving as ooxml will be pushed to the current version if and when resolved.
@Adhirath
When saving a range in docx format, all format information within the selected range will be saved together, and the data format within the range will be consistent with that in Excel. All bug fixes and feature enhancements are based on the latest version.
1 Like
great, any updates on this-
Issue ID(s): CELLSNET-52212 Support converting editable chart to docx
@Adhirath
We apologize, there is currently no update. Once we have any new information, we will share it with you. We will get back to you soon.