Recent

Author Topic: BackgroundColor for numeric cell  (Read 30240 times)

bigeno

  • Sr. Member
  • ****
  • Posts: 266
BackgroundColor for numeric cell
« on: February 10, 2013, 09:38:13 pm »
After generating xls file there is no background on numeric cell.

if I use:

   MyWorksheet.WriteUTF8Text(...)
   SCell:=MyWorksheet.GetCell(i,k);
   SCell^.BackgroundColor:=scPURPLE;
   SCell^.UsedFormattingFields := [uffBackgroundColor];

i get proper background, but if I use:

   MyWorksheet.WriteNumber(...)
   SCell:=MyWorksheet.GetCell(i,k);
   SCell^.BackgroundColor:=scPURPLE;
   SCell^.UsedFormattingFields := [uffBackgroundColor];

i don't get background.

BackgroundColor is only for string cells ?


felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: BackgroundColor for numeric cell
« Reply #1 on: February 12, 2013, 12:29:37 pm »
It should be fixed At revision: 2671

bigeno

  • Sr. Member
  • ****
  • Posts: 266
Re: BackgroundColor for numeric cell
« Reply #2 on: February 12, 2013, 08:29:42 pm »
Yes, works fine now. THX

thompsna

  • New member
  • *
  • Posts: 7
Re: BackgroundColor for numeric cell
« Reply #3 on: February 23, 2013, 12:41:25 am »
Hi, I'm having the same problem, but I don't under stand what you mean by "It should be fixed At revision: 2671."  Is that a future update coming out?

Sorry for my ignorance, I'm purely an amateur.

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: BackgroundColor for numeric cell
« Reply #4 on: February 23, 2013, 01:16:11 am »
It means that FPSpreadsheet has its own SVN repository. You can download its actual development version.
You need to have "subversion" installed. Tortoise SVN on Windows, or subversion package in Linux.

And link is on the wiki: http://wiki.freepascal.org/FPSpreadsheet#Subversion
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

thompsna

  • New member
  • *
  • Posts: 7
Re: BackgroundColor for numeric cell
« Reply #5 on: February 23, 2013, 05:09:03 pm »
Blaazen, thank you so much for the quick reply!  Unfortunately, I'm not a programmer (just a statistician) so I don't know how to do any of that.  I guess I'll have to wait until the next release.

thompsna

  • New member
  • *
  • Posts: 7
Re: BackgroundColor for numeric cell
« Reply #6 on: February 23, 2013, 06:13:59 pm »
OK, never mind... I was able to just go to the URL in my browser and download the files.  But I think I might have found another small issue.  Continuing the example from above, if I write

           MyCell := MyWorksheet.GetCell(row,14);
           MyCell^.BackgroundColor:=scPURPLE;
           MyCell^.UsedFormattingFields := [uffBackgroundColor];

...then it works.  However, if I write

           TempInt := 14;
           MyCell := MyWorksheet.GetCell(row,TempInt);
           MyCell^.BackgroundColor:=scPURPLE;
           MyCell^.UsedFormattingFields := [uffBackgroundColor];

...then it does not.  So I'm not able to use it when looping through an integer variable, which is what I need.  Moreover, the issue is only with the color.  If I do

           MyWorksheet.WriteUsedFormatting(row,TempInt, [uffBold]);

...it works fine.  Only the use of the integer variable with color.  Am I doing something incorrectly?

Thanks again for any help!

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: BackgroundColor for numeric cell
« Reply #7 on: February 23, 2013, 08:13:44 pm »
Am I doing something incorrectly?
I think you gave too little information to answer that. As someone who has never used FPSpreadsheet you speak of, seeing the whole procedure where that loop is, would help seeing programming errors. Also type and initialization of every variable you are using in it.

thompsna

  • New member
  • *
  • Posts: 7
Re: BackgroundColor for numeric cell
« Reply #8 on: February 23, 2013, 10:26:08 pm »
Thanks, but I don't think the loop is the issue because all the cell values display correctly, and Bold correctly.  Only the color doesn't show up.  Here is the original (abbreviated) code without the troubleshooting of TempInt above.  I am dumping values from an array and then want to highlight ones above a certain value; I can do so using Bold but not color.  Color does work if I simply replace "column" for that line with any actual number.  The many other things I am doing with fpspreadsheet work fine too; I love it.

Row, Column: integer;
FlagValue : real;
PropsArray: array of array of real; //setlength done elsewhere

  for Row := 1 to i do begin
      for Column := 1 to j do begin
       MyWorksheet.WriteNumber(row, column, PropsArray[row,column]);
       If PropsArray[row,column] > FlagValue then begin
           MyCell := MyWorksheet.GetCell(row,column);  //works with a number... everything else is fine
           MyCell^.BackgroundColor:=scPURPLE;
           MyCell^.UsedFormattingFields := [uffBackgroundColor];
           MyWorksheet.WriteUsedFormatting(row,column, [uffBold]);
           end;
      end; //Column
    end;  //Row

Is that sufficient?  Thank you for your time.
« Last Edit: February 23, 2013, 10:42:42 pm by thompsna »

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: BackgroundColor for numeric cell
« Reply #9 on: February 27, 2013, 04:01:43 pm »
Well, you do:

           MyCell^.UsedFormattingFields := [uffBackgroundColor];

And next thing you remove the background color with this command:

           MyWorksheet.WriteUsedFormatting(row,column, [uffBold]);

The correct would be:

           MyWorksheet.WriteUsedFormatting(row,column, [uffBackgroundColor, uffBold]);

It is a full list of all used formatting options. Not a addition over what is already there.

thompsna

  • New member
  • *
  • Posts: 7
Re: BackgroundColor for numeric cell
« Reply #10 on: March 28, 2013, 09:40:10 pm »
Perfect.  Thank you so much!

engranaje

  • Newbie
  • Posts: 6
built_in_colors in xlscommon.pas
« Reply #11 on: November 18, 2013, 10:08:13 am »
Hello:
  With de original BUILT_IN_COLOR constansts in  xlscommon.pas my code paints distinct colors. I must change the original constants values for obtain the color named by the constant. 
 
  // ORIGINAL  -> BUILT_IN_COLOR_PALLETE_RED  = $0A;  // FF0000H
  BUILT_IN_COLOR_PALLETE_RED       = $0C;

  // ORIGINAL  -> BUILT_IN_COLOR_PALLETE_BLUE       = $0C; // 0000FFH 
  BUILT_IN_COLOR_PALLETE_BLUE      = $0A;

  // ORIGINAL  -> BUILT_IN_COLOR_PALLETE_YELLOW      = $0D; // FFFF00H 
  BUILT_IN_COLOR_PALLETE_YELLOW    = $0F;
 
  // ORIGINAL  -> BUILT_IN_COLOR_PALLETE_CYAN    = $0F; // 00FFFFH
  BUILT_IN_COLOR_PALLETE_CYAN      = $0D;

  //-> ORIGINAL  -> BUILT_IN_COLOR_PALLETE_DARK_RED = $10; // 800000H 
  BUILT_IN_COLOR_PALLETE_DARK_RED  = $12;
 
  // ORIGINAL  -> BUILT_IN_COLOR_PALLETE_DARK_BLUE  = $12; // 000080H
  BUILT_IN_COLOR_PALLETE_DARK_BLUE = $10;

  // ORIGINAL  -> BUILT_IN_COLOR_PALLETE_OLIVE      = $13; // 808000H
  BUILT_IN_COLOR_PALLETE_OLIVE     = $15;
 
  // ORIGINAL  -> BUILT_IN_COLOR_PALLETE_TEAL      = $15;  // 008080H
  BUILT_IN_COLOR_PALLETE_TEAL      = $13; 
                                               
it's only my? any idea what's happens?
thank's

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: BackgroundColor for numeric cell
« Reply #12 on: November 24, 2013, 11:37:24 am »
@engranaje: what format are you trying to write (Excel 95, 97, xlsx, whatever)?
What spreadsheet (LibreOffice, Excel, OpenOffice), which version+operating system? are you using to open it and view the results?
Could you attach a small sample program that demonstrates the problem?
See also first link in my signature.

Note: you can use the [ code ] tags to make code snippets in posts readable, see the # button above when writing/editing posts.
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

engranaje

  • Newbie
  • Posts: 6
Re: BackgroundColor for numeric cell
« Reply #13 on: November 27, 2013, 12:48:46 pm »
Ok BigChimp thanks, i'm sorry. I paste here a little example procedure. With de original xlscommon.pas the 0,0 is not painted red, but with my xlscommon.pas works fine. Only need add fpspreadsheet to the uses.

Code: [Select]
procedure testBiff8CellBackgroundColor(sFullFileName:string);
const
  OUTPUT_FORMAT = sfExcel8;
var
  Workbook: TsWorkbook;
  Worksheet: TsWorksheet;
  Cell : PCell;
begin
  Workbook := TsWorkbook.Create;
  Worksheet := Workbook.AddWorksheet('testPage1');
  Worksheet.WriteNumber(0, 0, 12);

  Cell := Worksheet.GetCell(0, 0);
  Cell^.BackgroundColor :=  scRed;

  if  not (uffBackgroundColor in Cell^.UsedFormattingFields) then
    include (Cell^.UsedFormattingFields,uffBackgroundColor);

  Workbook.WriteToFile(sFullFileName, OUTPUT_FORMAT, TRUE);
  Workbook.free  ;

end;
                                                   
anyone with the same problem?, I'm working ok with my modified xlscommon.pas

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: BackgroundColor for numeric cell
« Reply #14 on: November 27, 2013, 04:57:17 pm »
That sample shows blue background color instead of the expected red for me (viewing with LibreOffice 4).

Going to have a look at the constant definitions.

The order of the palette in the original fpspreadsheet code does match the one specified in theopenoffice excel format pdf (linked to in the references in fpspreadsheet):
5.74.3 Built-In Default Colour Tables
=> I'll have a look at specifying the values in the enum and get back to you (if I don't, pls have a look at any updates for my code in my repository smalltools - see my other thread in fpspreadsheet). Thanks.
« Last Edit: November 27, 2013, 05:34:05 pm by BigChimp »
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

 

TinyPortal © 2005-2018