Hi John, sorry this is as much code as I can share but it has all the logic for getting the image. I have provided the screenshots and also the source documents to show the difference. Let me know what will help you understand it better
Hi I tried it out but still getting the exact same image. i replaced OnePagePerSheet = true with what you suggested. is there some other change needed as well?
I can see some issues in the generated image. e.g. words space issue. To make us be clear about your issues, please share us a screenshot that highlight the issue points in the generated image.
Thanks for your shared screenshot. Your issue is clear now.
Please try the following options for ImageOrPrintOptions
, it will get good result.
ImageOrPrintOptions originalImgOptions = new ImageOrPrintOptions
{
TextRenderingHint = TextRenderingHint.AntiAlias,
OnePagePerSheet = true,
ImageType = ImageType.OfficeCompatibleEmf,
};
outputTable.zip (3.5 KB)
thank you soo much, but I’m not able to add TextRenderingHint is it available only in the latest version?
The TextRenderingHint is only avaliable for windows target framework. If your project is running on Windows platform, please change TargetFramework to windows, e.g. change net8.0
to net8.0-windows
.
Hi guys, is there a way to find out if a cell belongs to a range? so if I have a cell C4 and I want to find out if it is part of a named range how can i do that?
@Adhirath
Please first obtain the named range by its name, and obtain the starting row, starting column, ending row, and ending column of the named range. Then obtain the row and column indexes of the cell, and compare them with the row and column indexes of the range to determine whether the cell is included in the range.
The sample code as follows:
Workbook workbook = new Workbook("book1.xlsx");
// Getting the specified named range
Range range = workbook.Worksheets.GetRangeByName("TestRange");
int startRow = range.FirstRow;
int startColumn = range.FirstColumn;
int endRow = range.FirstRow + range.RowCount - 1;
int endColumn = range.FirstColumn + range.ColumnCount - 1;
Worksheet sheet = range.Worksheet;
Cell c4 = workbook.Worksheets[0].Cells["C4"];
bool isInRange = false;
if (
c4.Worksheet.Name == sheet.Name
&& c4.Row >= startRow
&& c4.Row <= endRow
&& c4.Column >= startColumn
&& c4.Column <= endColumn
)
{
isInRange = true;
}
Console.WriteLine("c4 is in range: " + isInRange);
@Adhirath
There’s no good solution to check whether the cell belongs to which named range. We have to iterate all defined name to check it as the following codes:
private static Range Check(Workbook workbook, int row, int column)
{
foreach (Name name in workbook.Worksheets.Names)
{
Range range = name.GetRange();
if (range != null)
{
if (row >= range.FirstRow && row < range.FirstRow + range.RowCount
&& column >= range.FirstColumn && column < range.FirstColumn + range.ColumnCount)
{
return range;
}
}
}
return null;
}
This method is very inefficient, if you need to check cell many times, you should gather all defined named ranges at first.
And if you have other issues, please add a new post. Too many questions in a post will confuse us.
Will do, sorry about that!
Yes, please refer to the suggested code and write your own code for your needs to accomplish your task. In case you find any issue, kindly do provide details and sample code, we will check it soon.