I am evaluating the trial version of Aspose to see if we can replace our VBA system
Our current system copies Excel ranges and paste them in a word document as a picture,
VBA code: SomeRange.RefersToRange.CopyPicture Appearance:=xlPrinter, Format:=xlPictureRefersToRange.CopyPicture Appearance:=xlPrinter, Format:=xlPicture
The color font in the ranges automatically turns to black, while the color background remains intact. This is very important for the appearance of our docs. (see attached zip for sample image)
I used sheetRender.ToImage to get the images from Excel but can't find a way for the font color to appear as with VBA.
Do you have an equivalent of this functionality?
Hi,
Thanks for your posting and evaluating Aspose.Cells for .NET.
Please download and use the latest version:
Aspose.Cells
for .NET v7.2.0.3
It should work fine.
If the problem still persists with the above version, then please provide me your complete simpler runnable code replicating the problem and the source (xls/xlsx) documents if you are using any.
We will look into it and update you asap.
Downloaded latest, v7203. Same issue. Please see attached code and sample excel file.
Hi
We did not find issue in converted image from your xlsm file, please give us the correct image result.
See attached files and image results.
With Aspose, we would need the image to look like the one produced using VBA: VBA_image.emf
Hi,
Please try to set ws.PageSetup.BlackAndWhite = true;
That doesn’t return what we need, all background color disappears.
Hi,
Thanks for your feedback.
I have logged your comments in our database. We will look into your issue and get back to you asap.
This issue has been logged as CELLSNET-40627.
Hi,
We are afraid, we do not support this feature.
Please change the font color by yourself.
Please see the following code for your help.
C#
Workbook wbSource = new Workbook(@“D:\FileTemp\10-TT1025-104236-1.xlsm”);
Style style = wbSource.CreateStyle();
style.Font.Color = Color.Black;
StyleFlag flag = new StyleFlag();
flag.FontColor = true;
wbSource.Worksheets[0].Cells.ApplyStyle(style, flag);
wbSource.Worksheets[0].PageSetup.PrintArea = “C3:R55”;
ImageOrPrintOptions options = new ImageOrPrintOptions();
options.OnePagePerSheet = true;
options.ImageFormat = System.Drawing.Imaging.ImageFormat.Emf;
SheetRender sheetRender = new SheetRender(wbSource.Worksheets[0], options);
sheetRender.ToImage(0, @“D:\FileTemp\dest.emf”);
Shakeel, that would change ALL colors to black; how do I change all Blue, Red and Brown cells in the workbook to black using Aspose?
To change the color of an individual or a range of cells, you need to follow code as below. It converts the font color of Cells C6 to M15 to black using the Range class of Aspose.Cells.
//Instantiating a Workbook object
Workbook workbook = new Workbook(“C://10-TT1025-104236-1.xlsm”);
//Open the Second worksheet that contains the data
Worksheet sheet = workbook.Worksheets[1];
//Select the cells that need to be formatted
Range range = sheet.Cells.CreateRange(“C6:M15”);
//Define a style object
Aspose.Cells.Style style = new Style();
//Change the font color to black
style.Font.Color = System.Drawing.Color.Black;
//Apply the style to the selected Range
range.SetStyle(style);
//Saving the Excel file
workbook.Save(“C:\output.xls”);
In the same way, you can select Cells of your interest and format accordingly. I hope this helps you solve your solution. Let us know if we can be of additional help to you.
Thanks for using Aspose.Cells
Kashif, we have large workbooks with 70+ sheets. I would not know in advance the range so is there a way to change ALL cells in the whole workbook that are colored a specific color ( ex: blue or red ) only to black.
Hi,
Can you show us how can you achieve this using MS-Excel? Please accompany your reply with some screenshots. This will help us in assisting you better further.
Thanks
Hi,
I have analyzed your requirement, it is not possible to change color of all the cells which has some particular color.
I have logged a new feature requirement for this issue.
We will look into it and once the feature is implemented or we have some other update for you, we will let you know asap.
This issue has been logged as a New Feature Request with the id: CELLSNET-40679
I have illustrated your feature in the screenshot. Please have a look at it.
Screenshot:
We need to clarify: your screenshot points to background colors but the issue here is that we need to change Font color, not background color, of all the cells which has some particular color.
Please update the enhancement request. Thanks.
Hi,
Thanks for your clarification.
We will change the issue description accordingly.
I have discussed with the development team, currently Aspose.Cells does not support find and replace feature based on Styles.
So, we will look into it and if possible implement it.
We will update you asap.
The comment has been logged against the issue id: CELLSNET-40679
As a workaround suggested earlier to you also, you will have to iterate all cells, check their style and replace them.
I have attached a screenshot explaining your requirement for a reference.
Screenshot:
Hi,
Please use the following code. It will change the font color by iterating all cells.
I have attached the source file and the output file generated by this code.
Please see the screenshot for more illustration
C#
string filePath = @“F:\source.xlsx”;
//Load a source workbook
Workbook wb = new Workbook(filePath);
//Iterate all worksheets
for (int i = 0; i < wb.Worksheets.Count; i++)
{
Cells cells = wb.Worksheets[i].Cells;
//Set the font color of all the cells to black which has blue font color
for (IEnumerator ie = cells.GetEnumerator(); ie.MoveNext(); )
{
Cell cell = (Cell)ie.Current;
Style style = cell.GetStyle();
int rgb = style.Font.Color.ToArgb() & 0xFFFFFF;
if (rgb == (Color.Blue.ToArgb() & 0xFFFFFF))
{
style.Font.Color = Color.Black;
cell.SetStyle(style);
}//if
}//for
}//for
//Save the worbook
wb.Save(filePath + “.out.xlsx”);
Screenshot:
The issues you have found earlier (filed as CELLSNET-40679) have been fixed in this update.
This message was posted using Notification2Forum from Downloads module by Aspose Notifier.