Rich text problem

Questions and answers on how to use XLSReadWriteII 5.
Post Reply
Roman55
Posts: 10
Joined: Tue Mar 26, 2013 11:29 am

Rich text problem

Post by Roman55 »

Hello

I try to insert some rich text into a cell with this code:

Code: Select all

xlsRW.AsRichText[2, row] := '{\rtf1\ansi \ansicpg1252{\fonttbl{\f0\fnil Times New Roman}} \f0\fs22\ a \f0\fs22\  = 1000 }';
The result must be a simple text with a different font size for letter "a".
As for version 4, this works fine. After migrating to 5.10.08, I get an error:

Code: Select all

Exception EAccessViolation: Access violation at address 006F57C7 in module 'Myapp.exe'. Read of address 0000001C (OS exception)
  exception at $006F57C7 (module "Xc12DataStyleSheet5", proc "Xc12DataStyleSheet5.TXc12Font.GetName", unit "Xc12DataStylesheet5.pas", line 2927)
  Stack trace:
      Module "Xc12DataStyleSheet5", Procedure "Xc12DataStyleSheet5.TXc12Font.Equal", Unit "Xc12DataStylesheet5.pas", Line 2891
      Module "XLSSheetData5", Procedure "XLSSheetData5.TXLSWorksheet.RichTextLoadFromStream", Unit "XLSSheetData5.pas", Line 3246
      Module "XLSSheetData5", Procedure "XLSSheetData5.TXLSWorksheet.RichTextLoadFromStream", Unit "XLSSheetData5.pas", Line 3248
      Module "XLSSheetData5", Procedure "XLSSheetData5.TXLSWorksheet.SetAsRichText", Unit "XLSSheetData5.pas", Line 3502
      Module "XLSSheetData5", Procedure "XLSSheetData5.TXLSWorksheet.SetAsRichText", Unit "XLSSheetData5.pas", Line 3504
Is it something wrong with a font table? Tracing into TXLSWorksheet.RichTextLoadFromStream procedure reveals that parameter FR.Font is nil on this line

Code: Select all

FR[i].Font := FManager.StyleSheet.Fonts.Find(FR[i].Font);
Please check the issue.
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

Re: Rich text problem

Post by larsa »

Hello

The rich text parser is not perfect. Please use AsSimpleTags instead when creating cells with formatted text.

Code: Select all

    //* AsSimpleTags let you easily create formatted text with html-like tags.
    //* There are no end tags. A tag sets an option, and that option is used
    //* until a new tags replaces it. In order to write the "<", character,
    //* write an empty tag "<>" in the text. Example: 'Two <> one'
    //* The following tags can be uses:
    //*  <b>  Turn bold on.
    //* </b>  Turn bold off.
    //*  <i>  Turn italic on.
    //* </i>  Turn italic off.
    //*  <u>  Turn underline on.
    //* </u>  Turn underline off.
    //* <f:Font name> Changes the font name.
    //* <s:nn> Changes the font size. Setting the size to zero sets the font size to the default size.
    //* <c:xxxxxx> Changes the font color. The value xxxxxx is the hexadecimal RGB color value.
    //*            If xxxxxx is set to 'Auto', the default color will be used.
     property AsSimpleTags[ACol,ARow: integer]: AxUCString read GetAsSimpleTags write SetAsSimpleTags;
Lars Arvidsson, Axolot Data
Nevermind1003
Posts: 1
Joined: Mon Apr 15, 2013 7:24 am

Re: Rich text problem

Post by Nevermind1003 »

We had the same problem. A simple check if AItem <> nil in the following function was the solvation:

Code: Select all

function TXLSStyleObjectList.Find(AItem: TXLSStyleObject): TXLSStyleObject;
var
  Hash: PXLSHashItem;
begin
  if not FItemHashValid then
    UpdateItemHash;

  //>>> tw 150412 MT#0072982
  if AItem <> nil then
  //<<<
    Hash := FItemHash.Find(AItem)^
  //>>> tw 150412 MT#0072982
  else
    Hash := nil;
  //<<<
  if Hash <> Nil then
    Result := Hash^.Key
  else
    Result := Nil;
end;
Roman55
Posts: 10
Joined: Tue Mar 26, 2013 11:29 am

Re: Rich text problem

Post by Roman55 »

Nevermind1003, thanks for reply. I checked again and found AsRichText working in 5.10.16. It seems the parser has been fixed.
Post Reply