Recent

Author Topic: FPSpreadsheet 1.6: copy cell formatting  (Read 7743 times)

bonmario

  • Sr. Member
  • ****
  • Posts: 346
FPSpreadsheet 1.6: copy cell formatting
« on: August 28, 2015, 11:55:11 am »
Hi,
i've made a new project that do this
- read a ods file
- write in a new ods file all row that contains a specific word

I't works fine, but i'm unable to copy the cell formatting.

Someone can explain me how do this?

Thanks in advance, Mario

bonmario

  • Sr. Member
  • ****
  • Posts: 346
Re: FPSpreadsheet 1.6: copy cell formatting
« Reply #1 on: August 28, 2015, 04:07:18 pm »
I have solved using this cose:
Code: [Select]
                  OutWorksheet.WriteCellFormat(CurCell, WrkCellPart^.CellFormat);
                  OutWorksheet.WriteFont(CurCell, WrkCellPart^.Font.FontName, WrkCellPart^.Font.Size,
                                         WrkCellPart^.Font.Style, WrkCellPart^.Font.Color);

but i have a last problem: if a cell have more font or styles, this is non supported, FPSpreadsheet consider only one of them.

Thanks, Mario

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: FPSpreadsheet 1.6: copy cell formatting
« Reply #2 on: August 28, 2015, 05:14:18 pm »
There are several overloads of  a "CopyFormat" method of the worksheet:
Code: [Select]
var
  srccell, destcell: PCell;
begin
  srccell := OutWorksheet.WriteText(0, 0, 'This is a test');
  OutWorksheet.WriteFont(srccell, 'Arial', 16, [fssBold], scRed);
  destcell := OutWorksheet.WriteText(2, 2, 'copied format');
  OutWorksheet.CopyFormat(srccell, destcell);

As for your other question: fpspreadsheet does support several fonts within the same cell, but not in version 1.6. You'll have to go to the trunk version to get this feature. It is most easily applied if you disperse HTML code in the cell text and call the new text-writing method "WriteTextAsHTML". fpspreadsheet parses the cell text and creates the related "rich-text" parameters (see the examples in the "excel8write" demo):

Code: [Select]
  MyWorksheet.WriteTextAsHTML(2, 0, 'H<sub>2</sub>O');
  MyWorksheet.WriteTextAsHTML(3, 0, '<font color="red">red</font>, <font color="yellow">yellow</font>, <font color="green">green</font>');
  MyWorksheet.WriteTextAsHTML(4, 0, 'sin<sup>2</sup> &alpha; + cos<sup>2</sup> &beta; = 1');

See http://wiki.lazarus.freepascal.org/FPSpreadsheet#Rich-text_formatting

bonmario

  • Sr. Member
  • ****
  • Posts: 346
Re: FPSpreadsheet 1.6: copy cell formatting
« Reply #3 on: August 28, 2015, 06:50:43 pm »

OK thanks.
Since I use it at work, I prefer to use stable releases, then wait for the release of version 1.8.

Thanks again, Mario

bonmario

  • Sr. Member
  • ****
  • Posts: 346
Re: FPSpreadsheet 1.6: copy cell formatting
« Reply #4 on: August 31, 2015, 09:57:52 am »
Hi,
i'm trying to made a test with SVN version, but i can't understand how read cell formatting.
My problem is this: WriteText have a parameter "ARichTextParams", but ReadText havent'it.
How can i read "ARichTextParams" from the cell?

I've tried with this code, but don't work:
Code: [Select]
                  WrkCellPart:=MyWorksheet.GetCell(IdxRig, IdxCol);
                  OutWorksheet.WriteText(RigaOut, IdxCol, MyWorksheet.ReadAsText(IdxRig, IdxCol), WrkCellPart^.RichTextParams);

Thanks in advance, Mario
« Last Edit: August 31, 2015, 10:23:11 am by bonmario »

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: FPSpreadsheet 1.6: copy cell formatting
« Reply #5 on: August 31, 2015, 11:47:05 am »
I've tried with this code, but don't work
What is not working? Syntactically your code is correct. There is no reading method for the RichTextParams from the cell (just access them from the cell directly) because I thought nobody would need it. The reason is that the RichTextParams are specific to the text in the cell carrying them. A TRichTextParam is a record containing the font index to be used for the characters starting at the specified character index. Therefore it does not make sense to copy the RichTextParams to another cell having a different text. Except for "CopyCell" which duplicates a cell with all its contents and formatting to another place is working correctly, including RichTextParams because the text is the same in both cells.

bonmario

  • Sr. Member
  • ****
  • Posts: 346
Re: FPSpreadsheet 1.6: copy cell formatting
« Reply #6 on: August 31, 2015, 12:08:33 pm »
The problem is with words with "StrikeThrough", how this: testword.
When you wite the "<style:text-properties", you don't save the info "style:text-line-through-style"

Thanks, Mario

bonmario

  • Sr. Member
  • ****
  • Posts: 346
Re: FPSpreadsheet 1.6: copy cell formatting
« Reply #7 on: August 31, 2015, 02:01:12 pm »
I've made some other test.
I'm copying cells with this code:
Code: [Select]
OutWorksheet.CopyCell(IdxRig, IdxCol, RigaOut, IdxCol, MyWorksheet);
I've attached the result, created with a test file (From) that i'm trying to copy in a new file (To)

Thanks in advance, Mario

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: FPSpreadsheet 1.6: copy cell formatting
« Reply #8 on: August 31, 2015, 03:15:33 pm »
Aah! I see now that you may want to copy to another workbook. There, indeed, is a problem: The CopyCell procedure did not check that the fonts used by the rich-text parameters exist in the destination workbook and have the same index. Fixed in current reversion.

bonmario

  • Sr. Member
  • ****
  • Posts: 346
Re: FPSpreadsheet 1.6: copy cell formatting
« Reply #9 on: August 31, 2015, 03:39:40 pm »
Thanks, but there is some problem too in the font ed in the size.
I've attached the 2 files, from ad to.


Thanks again, Mario



wp

  • Hero Member
  • *****
  • Posts: 11916
Re: FPSpreadsheet 1.6: copy cell formatting
« Reply #10 on: August 31, 2015, 03:56:39 pm »
Please post also the code (.lpi, .lpr, .pas, .lfm) packed into a zip) which you are using to create these files. Important The code must show the issue and I must be able to compile it and step through it with the debugger.

bonmario

  • Sr. Member
  • ****
  • Posts: 346
Re: FPSpreadsheet 1.6: copy cell formatting
« Reply #11 on: August 31, 2015, 04:44:40 pm »
I've attached the project.

Thanks, Mario

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: FPSpreadsheet 1.6: copy cell formatting
« Reply #12 on: August 31, 2015, 11:41:01 pm »
Found it, a reading error for the ods file format. Fixed in r4309. But be warned: There's still a similar one in the xlsx reader...

Quote
When you wite the "<style:text-properties", you don't save the info "style:text-line-through-style"
Correct. The multitude of ways to strike-through or underline text in ods scared me. So far, I only implemented the single-strike-through and the single-underline because those are implemented in the canvas text painting methods - I need this for the visualization of the spreadsheets in the grid. Other styles may follow, but I can't tell you when.

bonmario

  • Sr. Member
  • ****
  • Posts: 346
Re: FPSpreadsheet 1.6: copy cell formatting
« Reply #13 on: September 01, 2015, 08:18:40 am »
Now it's perfect !!!!

Thanks again, Mario
« Last Edit: September 01, 2015, 08:28:19 am by bonmario »

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: FPSpreadsheet 1.6: copy cell formatting
« Reply #14 on: September 01, 2015, 12:57:16 pm »
But be warned: There's still a similar one in the xlsx reader...

No false alarm: The inconsistency that I saw is due to incorrect conversion of your From.ods file to xlsx by LibreOffice

 

TinyPortal © 2005-2018