Does anyone know how I can use matlab and activeX to add hyperlinks to powerpoint files?
There are two helpful posts on MatlabCentral, but they don't give me everything I need. The first explains how to create a powerpoint file using matlab: "Create Powerpoint Files with Matlab"
and the second shows how to use ActiveX to insert hyperlinks into Excel:"Add Hyperlink in Excel from Matlab" (See the second answer by Kaustubha)
I tried to merge the two answers. In powerpoint the slide objects have the .Hyperlinks attribute, but there is no .Add method for .Hyperlinks as there is in Excel.
Here is the code I have so far. I would like the link to appear in a table:
ppt = actxserver('PowerPoint.Application');
op = invoke(ppt.Presentations,'Add');
slide = invoke(op.Slides,'Add',1,1);
sH = op.PageSetup.SlideHeight; % slide height
sW = op.PageSetup.SlideWidth; % silde width
table = invoke(slide.Shapes, 'AddTable', 1, 3, 0.05*sW, sH*.2, 0.9*sW, sH*.60);
table.Table.Cell(1,1).Shape.TextFrame.TextRange.Text = 'www.stackoverflow.com';
% Add hyperlink to text in table using ActiveX
% slide.Hyperlinks - this exists but there is no add feature
invoke(op,'Save');
invoke(op,'Close');
invoke(ppt,'Quit');
delete(ppt);
Slide objects have a .Hyperlinks collection that you can examine to learn how many hyperlinks there are, where they point and so forth. To add a hyperlink you have to work with individual shapes or text ranges.
Sub AddAHyperlink()
Dim oSh As Shape
' As an example we're going to add hyperlinks to the
' currently selected shape.
' You could use any other method of getting a reference to
' a shape that you like, however:
Set oSh = ActiveWindow.Selection.ShapeRange(1)
' Add a hyperlink to the shape itself:
With oSh
.ActionSettings(1).Hyperlink.Address = "http://www.pptfaq.com"
' you can also add a subaddress if required
End With
' Or add the hyperlink to the text within the shape:
With oSh.TextFrame.TextRange
.Text = "Hyperlink me, daddy, 8 to the click"
.ActionSettings(1).Hyperlink.Address = "http://www.pptools.com"
End With
End Sub
To access the text within a table cell you'd do as you're already doing:
table.Table.Cell(1,1).Shape.TextFrame.TextRange
or
table.Table.Cell(1,1).Shape
or
Set oSh = table.Table.Cell(1,1).Shape
then use the same code as I've shown above
Not sure if this is still an active request from anyone and potentially the program capability has changed; but for anyone else that might be interested it does appear to be possible to add links.
Here is an example from some code I wrote...The slide number/item references will need to get updated for your task but I think it covers the key points. In this example the goal was to add a hyperlink to another slide within the presentation.
hyperlink_text = sprintf('%0.0f, %0.0f, %s', Presentation.Slides.Range.Item(3+i).SlideID, Presentation.Slides.Range.Item(3+i).SlideIndex,Presentation.Slides.Range.Item(3+i).Shapes.Item(2).TextFrame.TextRange.Text);
The hyperlink text will look something like this, as a text string. '250, 4, Slide Title'
Presentation.Slides.Range.Item(3).Shapes.Item(2).Table.Cell(1+i,1).Shape.TextFrame.TextRange.ActionSettings.Item(1).Hyperlink.SubAddress = hyperlink_text;
For internal links the Hyperlink.Address field can be left blank.
It appears that the only thing that was missing from the prior answers was that when using Matlab to execute the powerpoint VBA you need to use ActionSettings.Item(1) to refer to the mouseclick action instead of ActionSettings(1) that was shown from basic powerpoint VBA.
Hopefully this can be helpful for anyone else still looking.
Note that I am currently using Matlab R2017A and Powerpoint in Microsoft 365 ProPlus
Related
I have designed a document in Libre Office Draw, and now need to personalize it by filling certain controls (mainly labels) with names read from a text file.
Reading from a text file was trivial, but am facing difficulties in obtaining a reference to a control placed in a Libre Office Draw document; all the functions mentioned were related to controls placed on a dialog, and did not seem applicable in this case.
This might be the first lead into reaching my goal:
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
But then, how to find a control placed on 'document' named, say, "MyLabel1"? Once the label is filled, the document would need to be exported to PDF.
Thanks a lot!
To export a LO Draw document to PDF from Basic you can use the following code.
Sub ExportToPDF
sURL = convertToURL("d:\temp\lo_draw.pdf")
dim mFileType(0)
mFileType(0) = createUnoStruct("com.sun.star.beans.PropertyValue")
mFileType(0).Name = "FilterName"
mFileType(0).Value = "draw_pdf_Export"
thisComponent.storeToURL(sURL, mFileType())
End Sub
To figure out how to get access to the "labels" please provide a sample LO Draw document.
Im trying to make header and footer in excel via matlab using excel VBA. So far i did some manipulations with cells but header and footer is a problem.
Here is a code in matlab that opens actxserver and i tried this:
Excel = actxserver('Excel.Application');
Workbooks = Excel.Workbooks;
Excel.Visible = 0;
location=strcat(pwd,'\','testdoc.xlsx');
Workbook = Excel.Workbooks.Open(location);
%%
Excel.PageSetup.LeftHeader='TEST';
%%
Workbook.Save;
Excel.Quit;
I am trying to do next. I am trying to make header on the left,center and right side and make a footer with page number on center and two strings on right and left. Lets use this string 'TEST' for all operations in header and footer. I want to do this in matlab of course.
This is the reference https://msdn.microsoft.com/en-us/library/bb225426(v=office.12).aspx
And this is an example how it works in VBA but i dont know how to do that in matlab using actxserver.
Sub Date_Time()
ActiveSheet.PageSetup.CenterHeader = "&D &B&ITime:&I&B&T"
End Sub
Or:
Worksheets("SomeSheet").PageSetup.LeftHeader = "Some Text"
I am a bit confused. Tnx in advance.
You need to set headers and footers for an individual worksheet, not for Excel itself. So if Excel is your MATLAB variable representing a connection to Excel, you could within MATLAB use something like:
Excel.Worksheets.Item(1).PageSetup.CenterHeader = 'hello';
You can of course refer to Item(2) etc for later worksheets, and you can also use the ActiveSheet property of Excel rather than Worksheets.Item(1) to refer to the active worksheet (i.e. Excel.ActiveSheet.PageSetup.CenterHeader = ....
Hope that helps!
I am trying to flatten bitmap images in a PDF document as opposed to keep separatelayers. For example, let's say I have a document with two square images that are partially overlaying each other. I would like to merge them so that the user cannot individually select one of the squares to copy it out of the document. They'll be able to select both, I would think, but I don't want them to be able to isolate one of them. My client has a more complicated reason for wanting this restriction, but this is the simplest explanation. I would like to solve this with iTextSharp, but another product would be fine with me. I have used iTextSharp for form flattening, but I can't figure out how to flatten images. Thank you.
Edit
I realized another solution might just be to prevent selection within the document, which would hopefully prevent copying and pasting. I would guess that all document readers would not have to abide by my command to prevent selection, but as long as Adobe Reader (and maybe Foxit Reader) do abide by it, that should be good enough.
As you say you can use other products, I'll show a way to do merge layers using ABCpdf
Dim oDoc As New WebSupergoo.ABCpdf7.Doc
Using oDoc
oDoc.Read("D:\example.pdf")
Dim iTotal As Integer = oDoc.PageCount()
For i As Integer = 1 To iTotal
oDoc.PageNumber = 1
oDoc.Rendering.Save("D:\" & i & ".JPG")
oDoc.Delete(oDoc.Page)
Next
For i As Integer = 1 To iTotal
oDoc.AddPage()
oDoc.AddImage("D:\" & i & ".JPG")
oDoc.Flatten()
Next
oDoc.Save("D:\example_abc.pdf")
End Using
Original:
https://encodable.com/cgi-bin/filechucker.cgi?action=landing&path=/SOabcpdf/&file=example.pdf
Procesed:
https://encodable.com/cgi-bin/filechucker.cgi?action=landing&path=/SOabcpdf/&file=example_abc.pdf
You have to change the quality, reading ABCpdf Help.
http://www.websupergoo.com/helppdfnet/source/4-examples/19-rendering.htm
Edit:
As you don't want only merge image, but the copy protection, ABcPDF has this:
Dim oDoc As New WebSupergoo.ABCpdf7.Doc
Using oDoc
oDoc.Read("D:\example.pdf")
oDoc.Encryption.Type = 2
oDoc.Encryption.CanCopy = False
oDoc.Encryption.OwnerPassword = "password"
oDoc.Save("D:\example_abc.pdf")
End Using
Basically I have an excel file, and I read into one of my matlab variables a set of strings which are the headers for the columns of the data. Since this excel file is huge and I want to have the option to select which data to analyze at a given time I am hoping to take those strings/headers and have them appear on my gui with some check boxes buttons next to them so that I can pick which ones to work on ( i need the ability to select multiple data columns). This number of headers can change from file to file, so the number of list items and checkboxes will have to change on the gui based on the data file. Any ideas how to accomplish this? I can fill my gui with a bunch of text boxes and radio buttons but then i might end up with some that are empty, or end up with some that are to few, since the data file can have anywhere from 1-50 data columns each with their own header
Alternatively if anyone knows of a better way to have my user choose what data columns to act upon other than a ton of checkboxes, i'd be happy to hear it! This seemed like the most direct approach.
I tried what was suggested and get:
The code looks like:
[Data,Text] = xlsread('C:\data.csv');
a = Text(:,1);
b = strmatch('Channel Description',a);
Channels = Text(b,:);
[vals{1:numel(Channels,1)}]=deal(false);
foo= uitable('Data',vals,'ColumnEdit', true, 'RowName',Channels);
Here is an example using uitable, similar to excaza's comment but using the excel column headers as row names in the table:
[~,s,~] = xlsread('excelFile.xlsx', 1, 'A1:ZZ1');
[vals{1:numel(s),1}] = deal(false);
foo = uitable('Data', vals, 'ColumnEdit', true, 'RowName', s);
colsToLoad = foo.Data;
You will then need to either read the entire table and select columns in MATLAB using colsToLoad or loop over colsToLoad and read each column separately as xlsread does not support non-contiguous ranges.
[Data,Text] = xlsread('excelFile.xlsx');
dataToProcess = Data(:,[foo.Data{:}]);
I am working in an office automation tool to process PowerPoint documents, where I am facing an issue in formatting Chart.
I am using the following assemblies for formatting the Presentation
Microsoft.Office.Interop.PowerPoint Version: 12.0.0.0
Microsoft.Office.Interop.Graph Version: 12.0.0.0
Requirement is to apply some styles like Legend location, color, font etc to the Chart exists in the presentation.
I am able to verify the Shape like
shape.HasChart == MsoTriState.msoTrue
But not able to get the Chart object out of the shape
Tried the following code, but received OLEFormat exception
Graph.Chart chart = (Graph.Chart)shape.OLEFormat.Object
Thanks in advance for your help.
Resolved the issue by selecting correct reference from the COM tab.
Answer from thread - http://social.msdn.microsoft.com/Forums/en-US/officegeneral/thread/06cea2b7-f169-4f8a-b53e-4319b12b5450
I know you are asking from (rather) .NET point of view but I'll show you some code from VBA PowerPoint. My goal is to show you object hierarchy. I believe it would be helpful enough for you to solve your problem.
Sub Chart_Elements()
Dim CHRT As Chart
'first shape in the 1st slide is chart
Set CHRT = ActivePresentation.Slides(1).Shapes(1).Chart
With CHRT
'to set legend position
.Legend.Position = xlLegendPositionBottom
'to set size of 1st entry in legend
.Legend.LegendEntries(1).Font.Size = 10
'and so on
End With
End Sub
If that answer doesn't help you at all please consider re-tagging your question.