Created
April 28, 2024 15:58
-
-
Save MiranDaniel/a9cbba0bdf8763cf36a3fe11ed214a91 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
REM*****BASIC***** | |
Sub Main | |
On error resume next | |
Wait 100 | |
oDoc = ThisComponent | |
oSheet = oDoc.CurrentController.ActiveSheet | |
SD = oSheet.createSearchDescriptor() | |
SD.SearchRegularExpression = TRUE | |
SD.SearchCaseSensitive = FALSE | |
SD.SearchString = "jpg|gif|png|http" | |
Results = oSheet.findAll(SD) | |
If isNull(Results) then Exit Sub | |
RC = Results.Count | |
Dim Props(0) as new com.sun.star.beans.PropertyValue | |
Props(0).Name= "URL" | |
Dim Size as new com.sun.star.awt.Size | |
oProvider = createUnoService("com.sun.star.graphic.GraphicProvider") | |
'oFileAccess = CreateUnoService("com.sun.star.ucb.SimpleFileAccess") | |
m=0 | |
For k=0 to RC-1 | |
m=m+(Results(k).Rows.Count*Results(k).Columns.Count) | |
Next | |
SI = oDoc.CurrentController.StatusIndicator | |
SI.reset | |
SI.start(cStr(m), m) | |
n=0 | |
For k=0 to RC-1 | |
Cell = Results(k) | |
If Cell.supportsService("com.sun.star.table.Cell") then 'тогда это ячейка, а иначе это диапазон ячеек | |
s = ConvertToURL(Cell.String) | |
'If oFileAccess.exists(s) then | |
oShape = oDoc.createInstance("com.sun.star.drawing.GraphicObjectShape") | |
oSheet.DrawPage.add(oShape) | |
Props(0).Value = s | |
oShape.Graphic = oProvider.queryGraphic(Props()) | |
oShape.Name = Cell.AbsoluteName + "##" + Props(0).Value | |
oShape.Anchor = Cell | |
w = oShape.Graphic.Size.Width | |
h = oShape.Graphic.Size.Height | |
wcl = Cell.Size.Width*5 | |
hcl = Cell.Size.Height*5 | |
If w<>0 and h<>0 then | |
'Cell.String="" | |
Size.Width = hcl | |
Size.Height = hcl | |
If Size.Height > hcl then | |
Size.Width = hcl | |
Size.Height = hcl | |
Endif | |
oShape.setSize(Size) | |
'oShape.setPosition(Cell.Position) | |
erase oShape | |
Else | |
oShape.dispose() | |
Endif | |
n=n+1 | |
SI.setValue(n) | |
'SI.setText(cStr(n)+"/"+cStr(m)) | |
'Wait 10 | |
'Endif | |
Else | |
r = Cell.Rows.Count-1 | |
c = Cell.Columns.Count-1 | |
For i=0 to r | |
For j=0 to c | |
Cellij = Cell.getCellByPosition(j,i) | |
s = ConvertToURL(Cellij.String) | |
'If oFileAccess.exists(s) then | |
oShape = oDoc.createInstance("com.sun.star.drawing.GraphicObjectShape") | |
oSheet.DrawPage.add(oShape) | |
Props(0).Value = s | |
oShape.Graphic = oProvider.queryGraphic(Props()) | |
oShape.Name = Cellij.AbsoluteName + "##" + Props(0).Value | |
oShape.Anchor = Cellij | |
w = oShape.Graphic.Size.Width | |
h = oShape.Graphic.Size.Height | |
wcl = Cellij.Size.Width | |
hcl = Cellij.Size.Height | |
If w<>0 and h<>0 then | |
Cellij.String="" | |
Size.Width = wcl | |
Size.Height = h*wcl/w | |
If Size.Height > hcl then | |
Size.Width = hcl*w/h | |
Size.Height = hcl | |
Endif | |
oShape.setSize(Size) | |
'oShape.setPosition(Cellij.Position) | |
erase oShape | |
Else | |
oShape.dispose() | |
Endif | |
n=n+1 | |
SI.setValue(n) | |
'SI.setText(cStr(n)+"/"+cStr(m)) | |
'Wait 10 | |
'Endif | |
Next | |
Next | |
Endif | |
Next | |
SI.end | |
End Sub | |
Sub UpdateImages | |
oDoc = ThisComponent | |
oSheet = oDoc.CurrentController.ActiveSheet | |
Images = oSheet.DrawPage | |
Dim Size as new com.sun.star.awt.Size | |
SI = oDoc.CurrentController.StatusIndicator | |
SI.reset | |
SI.start(cStr(Images.Count), Images.Count) | |
For i=0 to Images.Count-1 | |
If Images(i).supportsService("com.sun.star.drawing.GraphicObjectShape") then | |
Parameters = Split(Images(i).Name,"##") | |
If ubound(Parameters)=1 then | |
'CellName = Parameters(0) | |
'ImageURL = Parameters(1) | |
Cell = Images(i).Anchor 'oSheet.getCellRangeByName(CellName) | |
'Images(i).Position = Cell.Position | |
w = Images(i).Graphic.Size.Width | |
h = Images(i).Graphic.Size.Height | |
wcl = Cell.Size.Width | |
hcl = Cell.Size.Height | |
Size.Height = h*wcl/w | |
If Size.Height > hcl then | |
Size.Width = hcl*w/h | |
Size.Height = hcl | |
Else | |
Size.Width = wcl | |
Endif | |
Images(i).Size = Size | |
Endif | |
Endif | |
SI.setValue(i+1) | |
Next | |
SI.end | |
End Sub | |
Sub IncreaseCells | |
oDoc = ThisComponent | |
oSheet = oDoc.CurrentController.ActiveSheet | |
Images = oSheet.DrawPage | |
DialogLibraries.LoadLibrary("replacelinkswithimages") | |
oDia = CreateUnoDialog(DialogLibraries.replacelinkswithimages.Dialog1) | |
If oDia.execute()=0 then Exit Sub | |
V = (100 + cLng(oDia.getControl("FormattedField1").Text))/100 | |
SI = oDoc.CurrentController.StatusIndicator | |
SI.reset | |
SI.start(cStr(Images.Count), Images.Count) | |
For i=0 to Images.Count-1 | |
If Images(i).supportsService("com.sun.star.drawing.GraphicObjectShape") then | |
Parameters = Split(Images(i).Name,"##") | |
If ubound(Parameters)=1 then | |
'CellName = Parameters(0) | |
'ImageURL = Parameters(1) | |
Cell = Images(i).Anchor'oSheet.getCellRangeByName(CellName) | |
Cell.Rows.Height = Cell.Rows.Height*V | |
Endif | |
Endif | |
SI.setValue(i+1) | |
Next | |
SI.end | |
UpdateImages | |
End Sub | |
Sub RestoreLinks | |
oDoc = ThisComponent | |
oSheet = oDoc.CurrentController.ActiveSheet | |
Images = oSheet.DrawPage | |
ic = Images.Count-1 | |
SI = oDoc.CurrentController.StatusIndicator | |
SI.reset | |
SI.start(cStr(Images.Count), Images.Count) | |
For i=ic to 0 step -1 | |
If Images(i).supportsService("com.sun.star.drawing.GraphicObjectShape") then | |
Parameters = Split(Images(i).Name,"##") | |
If ubound(Parameters)=1 then | |
'CellName = Parameters(0) | |
ImageURL = Parameters(1) | |
Cell = Images(i).Anchor 'oSheet.getCellRangeByName(CellName) | |
Cell.String = ImageURL | |
Images(i).dispose() | |
Endif | |
Endif | |
SI.setValue(ic-i+1) | |
Next | |
SI.end | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment