简体   繁体   English

LibreOffice 中使用宏的粗体文本 (LibreOffice Basic)

[英]Bold text in LibreOffice using macros (LibreOffice Basic)

I am doctor (X-ray).我是医生(X 射线)。 Asking my friend to create text macros for me to write protocols faster.让我的朋友为我创建文本宏以更快地编写协议。 I just wanted to push ALT+Q (or another letter).我只是想按 ALT+Q(或另一个字母)。 Then push ALT+number (from 0 to 9).然后按 ALT+数字(从 0 到 9)。 For each ALT+number I insert prepared text.对于每个 ALT+数字,我插入准备好的文本。 It is work.这是工作。 Part of inserted text should be bold.插入文本的一部分应为粗体。 I insert text, then select 2-3 words and press Ctrl+B.我插入文本,然后选择 2-3 个单词并按 Ctrl+B。 But I wanted to customised macro.但我想定制宏。

I need: vvod(0).Value = //bold "Вариант строения bold// — // regular один корень, один канал. regular//"我需要: vvod(0).Value = //bold "Вариант строения bold// — // 常规 один корень, один канал.常规//"

I tried to figure it out on my own, but I can't, because I'm a piece of shit.我试图自己弄清楚,但我做不到,因为我是一个狗屎。 Can someone tell me in which direction to think, because I'm stuck?有人可以告诉我该往哪个方向思考,因为我被卡住了吗?

I am attaching part of the code.我附上部分代码。

enter code here

    REM ***** BASIC ***** 

GLOBAL number as Integer 
GLOBAL vid as Integer 
public Sub Main 
End Sub 

public Sub ALTQ 
vid = 1 
End Sub 

public Sub ALTW 
vid = 2 
End Sub 

public Sub ALTE
vid = 3 
End Sub 

public sub ALT1 
number = 1 
solve() 
end sub 

public sub ALT2 
number = 2 
solve() 
end sub 

public sub ALT3 
number = 3 
solve() 
end sub 

public sub solve 
rem —-----------------------------------------------------------------------------------— 
rem Определение переменных и получение доступа к ним, не трогай 
dim document as object 
dim dispatcher as object 
document = ThisComponent.CurrentController.Frame 
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper") 
rem —---------------------------------------------------------— 
rem определение переменных, которые ты сам будешь создавать и использовать 
dim vvod(0) as new com.sun.star.beans.PropertyValue 
rem Name обязательно равняется ТЕКСТ 
vvod(0).Name = "Text" 
rem —------------------------------------------------------------------------------------— 

if vid = 1 Then 
if number = 1 Then 
vvod(0).Value = "коронковая часть реставрирована. " 
elseif number = 2 Then 
vvod(0).Value = "коронковая часть реставрирована пломбами. " 
elseif number = 3 Then 
vvod(0).Value = "депульпирован. Коронковая часть реставрирована. " 
End if 

I tried to figure it out myself and this is what I came up with:我试图自己弄清楚,这就是我想出的:

1) 1)

Dim sVar As String
sVar = "Это тест"
sVar.CharWeight = com.sun.star.awt.FontWeight.BOLD

error错误

2) 2)

Dim TextX As Object
TextX.String = "Это тест"
RectangleShape.CharWeight = com.sun.star.awt.FontWeight.BOLD
vvod(0).Value = TextX

error错误


I will be very grateful if you help me.如果您能帮助我,我将不胜感激。

I'm unable to give exact details because I don't use Libreoffice Basic but in python you need to grab the cursor and apply the font attributes to that.我无法提供确切的细节,因为我不使用 Libreoffice Basic,但在python中,您需要抓住cursor并将字体属性应用于该光标。
ie something along the lines of:即类似于以下内容:

desktop = XSCRIPTCONTEXT.getDesktop()
cursor = desktop.getCurrentComponent().getCurrentController().getViewCursor()
oFontWeight = cursor.CharWeight
Text_Weight = FontWeight.BOLD
cursor.CharWeight=Text_Weight
text.insertString(cursor, insert_text, 0)
cursor.CharWeight=oFontWeight

In principle, grab the current cursor and make a note of the current setting.原则上,抓住当前光标并记下当前设置。
Apply Bold text to the cursor粗体文本应用于光标
Insert text using the adjusted cursor使用调整后的光标插入文本
Reset cursor to previous text setting, or everything after this will be Bold .将光标重置为之前的文本设置,否则之后的所有内容都将变为粗体

ps I'm still grinning at your description of yourself. ps 我还在为你对自己的描述而微笑。 Good luck!祝你好运!

The above assumes:以上假设:

model = desktop.getCurrentComponent()
text = model.Text

and that you imported com.sun.star.awt.FontWeight并且您导入了com.sun.star.awt.FontWeight

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM