Free Support Forum - aspose.com

Can't update portion text

Hi

I am trying to update the portion of text in PowerPoint but its not getting updated where as the link is getting updated but not the text. I have portion.text to update the text value.

port.PortionFormat.HyperlinkManager.SetExternalHyperlinkClick(newDocumentUrl);
port.Text=port.Text.Replace(gatewayUrl, newDocumentUrl);

Port is the Portion. First line is working fine and second line is not working fine to replace the text.

This message was posted using Email2Forum by Imran Rafique. (private)
using (Aspose.Slides.Presentation presentation1 = new Aspose.Slides.Presentation(fileName))
{
// Iterate through all the slide parts in the presentation part.

foreach (Aspose.Slides.Slide slide in presentation1.Slides)
{

List HypLinks = new List();

//Get an Array of TextFrameEx objects from the first slide
ITextFrame[] textFramesSlideOne = Aspose.Slides.Util.SlideUtil.GetAllTextBoxes(slide);
try
{
//Loop through the Array of TextFrames
for (int i = 0; i < textFramesSlideOne.Length; i++)
{
try
{
//Loop through paragraphs in current TextFrame
foreach (Aspose.Slides.Paragraph para in textFramesSlideOne[i].Paragraphs)
{
//Loop through portions in the current Paragraph
foreach (Portion port in para.Portions)
{
try
{
if (port.PortionFormat.AsIHyperlinkContainer.HyperlinkClick != null)
{
if (port.PortionFormat.AsIHyperlinkContainer.HyperlinkClick.ExternalUrl != null)
{
HypLinks.Add(port.PortionFormat.AsIHyperlinkContainer.HyperlinkClick.ExternalUrl);
string gatewayUrl = port.PortionFormat.AsIHyperlinkContainer.HyperlinkClick.ExternalUrl;
//gatewayUrl = "http://gateway/sites/Home/consumerbusiness/default.aspx";
if (gatewayUrl.Contains("http://gateway") || gatewayUrl.Contains("http://portail"))
{
if (gatewayUrl.ToLower().LastIndexOf('.') >= 0)
{
//if (gatewayUrl.ToLower().Substring(gatewayUrl.ToLower().LastIndexOf('.')) == ".ppt" || gatewayUrl.ToLower().Substring(gatewayUrl.ToLower().LastIndexOf('.')) == ".pptx" || gatewayUrl.ToLower().Substring(gatewayUrl.ToLower().LastIndexOf('.')) == ".doc" || gatewayUrl.ToLower().Substring(gatewayUrl.ToLower().LastIndexOf('.')) == ".docx" || gatewayUrl.ToLower().Substring(gatewayUrl.ToLower().LastIndexOf('.')) == ".xls" || gatewayUrl.ToLower().Substring(gatewayUrl.ToLower().LastIndexOf('.')) == ".xlsx" || gatewayUrl.ToLower().Substring(gatewayUrl.ToLower().LastIndexOf('.')) == ".pdf")
//if (gatewayUrl.Contains(".pdf") || gatewayUrl.Contains(".doc") || gatewayUrl.Contains(".docx") || gatewayUrl.Contains(".xls") || gatewayUrl.Contains(".xlsx") || gatewayUrl.Contains(".ppt") || gatewayUrl.Contains(".pptx"))
{

string newDocumentUrl = GetmyDeloitteDocumentUrl(pageUrl, gatewayUrl, logfile, exLog, dtDocumentUrls, dtPageUrls);
port.PortionFormat.HyperlinkManager.SetExternalHyperlinkClick(newDocumentUrl);
//port.Text=port.Text.Replace(gatewayUrl, newDocumentUrl);
para.Text = para.Text.Replace(gatewayUrl, newDocumentUrl);
}
//else
//{
// string newPageUrl = GetmyDeloittePageUrl(pageUrl, gatewayUrl, exLog, dtPageUrls);
// port.PortionFormat.HyperlinkManager.SetExternalHyperlinkClick(newPageUrl);
//}
}
else
{
string newPageUrl = GetmyDeloittePageUrl(pageUrl, gatewayUrl,logfile, exLog, dtPageUrls);
port.PortionFormat.HyperlinkManager.SetExternalHyperlinkClick(newPageUrl);
port.Text= port.Text.Replace(gatewayUrl, newPageUrl);
//para.Text = para.Text.Replace(gatewayUrl, newPageUrl);
}
//port.PortionFormat.HyperlinkManager.SetExternalHyperlinkClick("http://mydeloitte.com");
found = true;
count++;
}
}
//else
//{
// Console.WriteLine("Test");
//}
}
else if (port.Text.Contains("http://gateway") || port.Text.Contains("http://portail"))
{
foreach (Match m in Regex.Matches(port.Text, @"((http[s]?|ftp):\/)?\/?([^:\/\s]+)(:([^\/]*))?((\/\w+)*\/)([\w\-\.]+[^#?\s]+)(\?([^#]*))?(#(.*))?$"))
{
string gatewayUrl = m.ToString().Trim().ToLower();
if (gatewayUrl.IndexOf("?") == gatewayUrl.Length - 1)
{
gatewayUrl = gatewayUrl.Replace("?", "");
}
if (gatewayUrl.IndexOf(".") == gatewayUrl.Length - 1)
{
gatewayUrl = gatewayUrl.Replace(".", "");
}

if (gatewayUrl.ToLower().LastIndexOf('.') >= 0)
{
string newDocumentUrl = GetmyDeloitteDocumentUrl(pageUrl, gatewayUrl, logfile, exLog, dtDocumentUrls, dtPageUrls);
port.Text=port.Text.ToLower().Replace(gatewayUrl, newDocumentUrl);
//para.Text = para.Text.Replace(gatewayUrl, newDocumentUrl);
found = true;
count++;
}
else
{
string newPageUrl = GetmyDeloittePageUrl(pageUrl, gatewayUrl, logfile, exLog, dtPageUrls);
port.Text=port.Text.ToLower().Replace(gatewayUrl, newPageUrl);
//para.Text = para.Text.Replace(gatewayUrl, newPageUrl);
found = true;
count++;
}
}
}
}
catch (Exception ex)
{
throw;
}
}
}
}
catch (Exception ex)
{
throw;
}
}
}
catch (Exception ex)
{
throw;
}
}

Hi Nagesh,


Thank you for considering Aspose.Slides.

I have observed your comments and like to request you to please try using following sample code. It updates the hyperlink as well as the portion text.

Presentation pptxPresentation = new Presentation(“D:\test.pptx”);

List HypLinks = new List();

//Get an Array of TextFrame objects from the first slide
ITextFrame[] textFramesSlideOne = Aspose.Slides.Util.SlideUtil.GetAllTextBoxes(pptxPresentation.Slides[0]);

//Loop through the Array of TextFrames
for (int i = 0; i < textFramesSlideOne.Length; i++)

//Loop through paragraphs in current TextFrame
foreach (Paragraph para in textFramesSlideOne[i].Paragraphs)

//Loop through portions in the current Paragraph
foreach (Portion port in para.Portions)
{
if (port.PortionFormat.AsIHyperlinkContainer.HyperlinkClick != null)
{
HypLinks.Add(port.PortionFormat.AsIHyperlinkContainer.HyperlinkClick.ExternalUrl);
port.PortionFormat.HyperlinkManager.SetExternalHyperlinkClick(“customURL.com”);
port.Text = “customtext”;
}
}
pptxPresentation.Save(@“D:\test.pptx”, Aspose.Slides.Export.SaveFormat.Pptx);

I hope this will be helpful. Please share if I may help you further in this regard.

Best Regards,

The issues you have found earlier (filed as WORDSNET-16228) have been fixed in this Aspose.Words for .NET 20.10 update and this Aspose.Words for Java 20.10 update.