.Net Core SDK, cannot set text property

Ilya Sokolov is at rula-tech.com
Fri Mar 28 06:13:56 UTC 2025


Also speaking of  the first issue: the code which reproduces the issue in
the WriterDemo.cs looks like:

// Create a cursor object
XTextCursor cursor = simpleText.createTextCursor();

cursor.query<XPropertySet>().setPropertyValue("CharWeight", new
Any(((float)200)));
cursor.query<XPropertySet>().setPropertyValue("CharEscapement", new
Any((Int16)0));
*cursor.query<XPropertySet>().setPropertyValue("CharEscapementHeight", new
Any((Byte)100));*


// Inserting some Text
text.insertString(cursor, "The first line in the newly created text
document.\n", false);

The 'Object reference not set to an instance of an object.' occurs on
the cursor.query<XPropertySet>().setPropertyValue("CharEscapementHeight",
new Any((Byte)100)); line.


On Fri, Mar 28, 2025 at 8:35 AM Ilya Sokolov <is at rula-tech.com> wrote:

> Hello,
>
> It seems there is another issue with the .Net Core SDK.
>
> There is a need to set with of the column of a table. There is a function,
> which sets the width of a table column, listed below. The function is
> converted from the code, which works with the .Net Framework SDK.
>
> void SetColumnWidth(XTextTable textTable,int ColNum, short Width)
> {
>     Any obj =
> textTable.query<XPropertySet>().getPropertyValue("TableColumnSeparators");
>     TableColumnSeparator[] tcs = (TableColumnSeparator[])(obj.Value);
>     short Delta = 0;
>     if (tcs != null)
>     {
>         if (tcs.Length - 1 >= ColNum)
>         {
>             if (ColNum == 0)
>             {
>                 Delta = (short)(Width - tcs[ColNum].Position);
>                 tcs[ColNum].Position = Width;
>             }
>             else
>             {
>                 Delta = (short)(Width - (tcs[ColNum].Position -
> tcs[ColNum].Position));
>                 tcs[ColNum].Position = (short)(Width + tcs[ColNum -
> 1].Position);
>             }
>         }
>
>         Any val = new
> Any(typeof(com.sun.star.text.TableColumnSeparator[]), tcs);
>
> textTable.query<XPropertySet>().setPropertyValue("TableColumnSeparators",
> val);
>     }
> }
>
> If the function is called in
> \sdk\examples\dotnet\WriterDemo\csharp\WriterDemo.cs, like listed below:
>
> // Get first row
> XTableRows tableRows = textTable.getRows();
> Any rowAny = tableRows.query<XIndexAccess>().getByIndex(0);
>
> *SetColumnWidth(textTable, 1, 200);*
>
> // Set a different background color for the first row
> XPropertySet firstRowPropertySet = rowAny.cast<XPropertySet>();
> firstRowPropertySet.setPropertyValue("BackTransparent", new Any(false));
>
>
> It gives an access violation error ("Attempted to read or write protected
> memory. This is often an indication that other memory is corrupt") on the
> line
>
>  textTable.query<XPropertySet>().setPropertyValue("TableColumnSeparators",
> val);
>
> When I tried to get the columns of the table via the code below (the code
> is inserted in the  WriterDemo.cs  example too):
>
> // Set the table background color
> XPropertySet tablePropertySet = textTableI.query<XPropertySet>();
> tablePropertySet.setPropertyValue("BackTransparent", new Any(false));
> tablePropertySet.setPropertyValue("BackColor", new Any(0xCCCCFF));
>
>
> *XTableColumns tableCols = textTable.getColumns();Any colAny =
> tableCols.query<XIndexAccess>().getByIndex(1);*
>
> // Get first row
> XTableRows tableRows = textTable.getRows();
> Any rowAny = tableRows.query<XIndexAccess>().getByIndex(0);
>
>
> However, the   tableCols.query<XIndexAccess>().getByIndex(1) line give
> another error:
>
> Exception thrown: 'System.ArgumentException' in net_basetypes.dll
> An unhandled exception of type 'System.ArgumentException' occurred in
> net_basetypes.dll
> Value of Any can only be null if Type is void. Perhaps you want Any.VOID?
>
>
> Could you tell me what is a proper way to change the table column width
> using the .Net Core SDK?
>
>
> On Thu, Mar 27, 2025 at 6:28 PM Ilya Sokolov <is at rula-tech.com> wrote:
>
>> Hello
>>
>> I am trying to use the .Net Core SDK and  try to run some program, which
>> previously run on .Net Framework.
>>
>> There is a strange issue here: there are two properties of a
>> character, CharEscapement and CharEscapementHeight, they are set like
>>
>>  XText DocText = m_Doc.query<XTextDocument>().getText();
>> m_TextCursor = DocText.createTextCursor();
>>
>> XPropertySet CurObject = m_TextCursor.query<XPropertySet>();
>>
>> CurObject.setPropertyValue("CharEscapement", new Any((Int16)0));
>>
>> CurObject.setPropertyValue("CharEscapementHeight", new Any((Byte)100));
>>
>> And the CharEscapement is set successfully, but an : 'Object reference
>> not set to an instance of an object.' exception occurres when the second
>> property is set.
>>
>> Could you tell me if there is a known workaround about the issue?
>>
>>
>>
>> --
>> Best Regards,
>> Ilia Sokolov
>>
>>
>
> --
> Best Regards,
> Ilia Sokolov
>
>

-- 
Best Regards,
Ilia Sokolov

Head of Software Development
RULA Technologies SIA
Balta Iela 7, Riga, LV-1055, Latvia
+371 66102184
http://rula-tech.com
E-mail: is at rula-tech.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/libreoffice/attachments/20250328/c9c5a2c5/attachment.htm>


More information about the LibreOffice mailing list