Hello team,
I have converted P0_01.xlsx to a image with Aspose.Cells. Please find a error point with P0_01_00000001.jpg.
1) Shade has appeared.
This is my code.
--------------------
public static List ConvertExcelToImage(string docName, MemoryStream docStream, Dictionary config)
{
try
{
var pageInfoList = new List();
// Get config setting
string docRootDir = config[“DocumentsFilePath”];
int dpi = int.Parse(config[“ImageDPI”]);
int thumbMaxH = int.Parse(config[“ThumbnailMaxHeight”]);
int thumbMaxW = int.Parse(config[“ThumbnailMaxWidth”]);
int maxPageNum = int.Parse(config[“DocumentMaxPageNum”]);
double readScale = double.Parse(config[“ImageReadScale”]);
int readDpi = Convert.ToInt32(dpi * readScale);
// Create images directory
string pageImgDir = docRootDir;
if (!Directory.Exists(pageImgDir))
Directory.CreateDirectory(pageImgDir);
// Get the encoder of JPEG
ImageCodecInfo jpgEncoder = GetCodecInfo();
//EncoderParameters encParams = GetEncoderParams();
EncoderParameters encParams = GetEncoderParams(int.Parse(config[“ImageJpegQuality”]));
// Instantiate the License class
Aspose.Cells.License license = new Aspose.Cells.License();
license.SetLicense(“Aspose.Total.lic”);
// Convert .doc and .docx file to PDF.
Workbook book = new Workbook(docStream);
//Define ImageOrPrintOptions
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
//Specify the image format
imgOptions.ImageFormat = ImageFormat.Png;
imgOptions.VerticalResolution = readDpi;
imgOptions.HorizontalResolution = readDpi;
int totalPageCount = 0;
foreach (Worksheet sheet in book.Worksheets)
{
//Render the sheet with respect to specified image/print options
SheetRender sr = new SheetRender(sheet, imgOptions);
for (int i = 0; i
{
totalPageCount++;
if (totalPageCount <= maxPageNum)
{
//Render the image for the sheet
string imgFile = string.Format("{0}_{1:D8}.jpg",
Path.GetFileNameWithoutExtension(docName), totalPageCount);
string imgPath = Path.Combine(pageImgDir, imgFile);
using (Bitmap bitmap = sr.ToImage(i))
{
// Export image file
bitmap.SetResolution(dpi, dpi);
bitmap.Save(imgPath, jpgEncoder, encParams);
// Export thumbnail file
//string thumbFilename = string.Format(@"{0}_thumb.jpg", Path.GetFileNameWithoutExtension(imgPath));
//string thumbPath = Path.Combine(Path.GetDirectoryName(imgPath), thumbFilename);
//float scale = (float)Math.Min((double)thumbMaxW / bitmap.Width, (double)thumbMaxH / bitmap.Height);
//int thumbW = System.Convert.ToInt32(bitmap.Width * scale);
//int thumbH = System.Convert.ToInt32(bitmap.Height * scale);
//using (Bitmap thumbBmp = new Bitmap(thumbW, thumbH))
//{
// thumbBmp.SetResolution(dpi, dpi);
// using (Graphics graph = Graphics.FromImage(thumbBmp))
// {
// graph.DrawImage(bitmap, 0, 0, thumbW, thumbH);
// }
// thumbBmp.Save(thumbPath, jpgEncoder, encParams);
//}
// TODO Create OCR XML
// Add PageInfo List
pageInfoList.Add(imgPath);
}
}
else
{
break;
}
}
if (totalPageCount >= maxPageNum) break;
}
// return results with flag of max page limit over
return pageInfoList;
}
finally
{
}
}
-------------
They are parameters.
// Get config setting
Create Appseting key value for async function
Dictionary<string, string> config = new Dictionary<string, string>();
config.Add(“DocumentsFilePath”, outDir);
config.Add(“ImageDPI”, “96”);
config.Add(“ImageReadScale”, “1.25”);
config.Add(“ThumbnailMaxHeight”, “252”);
config.Add(“ThumbnailMaxWidth”, “210”);
config.Add(“ImageJpegQuality”, “80”);
config.Add(“DocumentMaxPageNum”, “1000”);
---------------------------------------
Thank you,
PFU DSOL2
Hi,
Thanks for your posting and using Aspose.Cells.
We have looked into this issue and found that you should calculate formula before saving to image.
So, please change these lines of code
// Convert .doc and .docx file to PDF.
Workbook book = new Workbook(docStream);
into these lines
// Convert .doc and .docx file to PDF.
Workbook book = new Workbook(docStream);
book.CalculateFormula();
and it should fix your issue. Let us know your feedback.
Hello team,
Sorry for the late reply.
It works well in my environment.
Thank you,
PFU DSOL2
Thanks for your feedback and using Aspose.Cells.
It is good to know that your issue is resolved now. Let us know if you encounter any other issue, we will be glad to look into it and help you further.