Recent

Author Topic: FPSpreadsheet: AV on TWorkbook.WriteToFile()  (Read 1519 times)

JP-CASSOU

  • New member
  • *
  • Posts: 7
FPSpreadsheet: AV on TWorkbook.WriteToFile()
« on: July 13, 2023, 11:22:15 am »
Hello,

Using TWorkbook:

When not use FWorkbook.AddCellFormat(), I obtains 'List index out of bounds'

Else, I obtains 'Access violation' using TWorkbook.WriteToFile()

wp

  • Hero Member
  • *****
  • Posts: 11996
Re: FPSpreadsheet: AV on TWorkbook.WriteToFile()
« Reply #1 on: July 13, 2023, 11:34:55 am »
Sorry, this is not enough information. Post a SMALL (!) project demonstrating the issue.

JP-CASSOU

  • New member
  • *
  • Posts: 7
Re: FPSpreadsheet: AV on TWorkbook.WriteToFile()
« Reply #2 on: July 13, 2023, 01:13:19 pm »
If CS.SetBorders specified : -> Access Violation, else OK

Code: Pascal  [Select][+][-]
  1. var
  2.   CS: TsCellFormat;  // TsCellFormat est un record
  3.   BS: TsCellBorderStyles;
  4. begin    
  5.    BS := DEFAULT_BORDERSTYLES;
  6.  
  7.     CS.Name := AStyleName;
  8.     CS.ID   := FWorkbook.GetNumCellFormats();
  9.     CS.VertAlignment := TsVertAlignment.vaCenter;
  10.  
  11.  
  12.  
  13.     CS.SetBackground(TsFillStyle.fsSolidFill, ACellColor, ACellColor);
  14.     CS.SetFont(0);
  15.     CS.SetNumberFormat(0);
  16.     CS.SetHorAlignment(TsHorAlignment.haDefault);
  17.     CS.SetVertAlignment(TsVertAlignment.vaDefault);
  18.     CS.SetTextRotation(TsTextRotation.trHorizontal);
  19.  
  20.     // CS.SetBorders([]); // <-- AV in WriterToFile if specified
  21.  
  22.     FWorkbook.AddCellFormat(CS);    
  23.  
  24.  
                     

Additionnally, how to specify OOo Styles ?                             

wp

  • Hero Member
  • *****
  • Posts: 11996
Re: FPSpreadsheet: AV on TWorkbook.WriteToFile()
« Reply #3 on: July 13, 2023, 03:28:11 pm »
Please post a compilable project. The project that I create from your snippet works correctly.

Code: Pascal  [Select][+][-]
  1. program Project1;
  2.  
  3. uses
  4.   fpspreadsheet, fpstypes, fpsallformats;
  5. var
  6.   FWorkbook: TsWorkbook;
  7.   FWorksheet: TsWorksheet;
  8.   FCell: PCell;
  9.   CS: TsCellFormat;  // TsCellFormat est un record
  10.   BS: TsCellBorderStyles;
  11.   ACellColor: TsColor;
  12.   idx: Integer;
  13. begin
  14.   ACellColor := scRed;
  15.  
  16.   FWorkbook := TsWorkbook.Create;
  17.   try
  18.     FWorksheet := FWorkbook.AddWorksheet('Page 1');
  19.  
  20.     BS := DEFAULT_BORDERSTYLES;
  21.  
  22. //    CS.Name := AStyleName;
  23.     CS.ID   := FWorkbook.GetNumCellFormats();
  24.     CS.VertAlignment := TsVertAlignment.vaCenter;
  25.     CS.SetBackground(TsFillStyle.fsSolidFill, ACellColor, ACellColor);
  26.     CS.SetFont(0);
  27.     CS.SetNumberFormat(0);
  28.     CS.SetHorAlignment(TsHorAlignment.haDefault);
  29.     CS.SetVertAlignment(TsVertAlignment.vaDefault);
  30.     CS.SetTextRotation(TsTextRotation.trHorizontal);
  31.     CS.SetBorders([]);
  32.  
  33.     idx := FWorkbook.AddCellFormat(CS);
  34.  
  35.     FCell := FWorksheet.WriteText(0, 0, 'Test');
  36.     FWorksheet.WriteCellFormat(FCell, FWorkbook.GetCellFormat(idx));
  37.  
  38.     FWorkbook.WriteToFile('test.xlsx', true);
  39.  
  40.   finally
  41.     FWorkbook.Free;
  42.   end;
  43. end.                              

Additionnally, how to specify OOo Styles ?                             
FPSpreadsheet does not support the "Styles" introduced by Excel and LibreOffice. Every cell must be formatted individually.

 

TinyPortal © 2005-2018