Hi,
We have visio file and that file have ‘.xlsx’ file. So we collect the ‘.xlsx’ shapes then set Forgroundcolor. FInally save the Visio file, but Still the foreground color not updated .
private void TestVisioExcelBold(string strInputFile, string strOutputPath)
{
FileStream _licenseStream = new FileStream("Aspose.Total.lic", FileMode.Open);
License licDiagram = new License();
licDiagram.SetLicense(_licenseStream);
_licenseStream.Position = 0;
Aspose.Cells.License licCell = new Aspose.Cells.License();
licCell.SetLicense(_licenseStream);
{
Diagram diagram = new Diagram(strInputFile, LoadFileFormat.VSDX);
foreach(Page diagramPage in diagram.Pages)
{
foreach(Shape OLE_Shape in diagramPage.Shapes)
{
if(OLE_Shape.Type == TypeValue.Foreign)
{
if(OLE_Shape.ForeignData.ForeignType != ForeignType.Object) continue;
if(OLE_Shape.ForeignData.ObjectData == null) continue;
Stream Ole_stream = new MemoryStream(OLE_Shape.ForeignData.Value);
// Get format of the OLE file object
FileFormatInfo info = FileFormatUtil.DetectFileFormat(Ole_stream);
if(info.LoadFormat == LoadFormat.Xlsx || info.LoadFormat == LoadFormat.Excel97To2003)
{
// Modify an OLE object
Workbook workbook = new Workbook(new MemoryStream(OLE_Shape.ForeignData.Value));
foreach(Cell cell in workbook.Worksheets[0].Cells)
{
var style = cell.GetStyle();
style.ForegroundColor = System.Drawing.Color.LightGreen;
style.Pattern = BackgroundType.Solid;
cell.SetStyle(style);
}
ImageOrPrintOptions options = new ImageOrPrintOptions
{
OnePagePerSheet = true,
ImageType = ImageType.Png,
OnlyArea = true,
IsCellAutoFit = true,
Transparent = true,
HorizontalResolution = 200,
VerticalResolution = 200
};
SheetRender sr = new SheetRender(workbook.Worksheets[0], options);
sr.ToImage(0, "outputConvertWorksheettoImageFile.emf");
using(FileStream fs = new FileStream("outputConvertWorksheettoImageFile.emf", FileMode.OpenOrCreate, FileAccess.ReadWrite))
{
byte[] buff = new byte[fs.Length];
fs.Read(buff, 0, (int) fs.Length);
MemoryStream streamEmf;
using(streamEmf = new MemoryStream(buff))
{
// Replace picture shape
OLE_Shape.ForeignData.ImageData = streamEmf.ToArray();
}
}
MemoryStream outStream = new MemoryStream();
workbook.Save(outStream, SaveFormat.Xlsx);
OLE_Shape.ForeignData.ObjectData = outStream.ToArray();
workbook.Save("C:\\Users\\VenkadachalapathyKal\\OneDrive - M&S\\Desktop\\Style\\" + "Test" + ".xlsx", SaveFormat.Xlsx);
}
}
}
}
ImageSaveOptions opt = new ImageSaveOptions(SaveFileFormat.PNG)
{
SmoothingMode = SmoothingMode.HighQuality,
CompositingQuality = CompositingQuality.HighQuality,
InterpolationMode = InterpolationMode.HighQualityBicubic,
PixelOffsetMode = PixelOffsetMode.HighQuality,
EnlargePage = false,
Resolution = 96,
PageIndex = 0
};
// Save Visio diagram
diagram.Save(strOutputPath + $"{Path.GetFileNameWithoutExtension(strInputFile)}_{DateTime.Now.ToString("yyyyMMddHHmmss")}_out.vsdx", SaveFileFormat.VSDX);
diagram.Save(strOutputPath + $"{Path.GetFileNameWithoutExtension(strInputFile)}_{DateTime.Now.ToString("yyyyMMddHHmmss")}_out.png", opt);
}
}
TestVisio_20230330120652_out.zip (77.3 KB)
TestVisio_20230330120653_out.png (3.7 KB)
Could you please help us to resolve this.