Forum > FPvectorial
[SOLVED] Adding columns to a Word document table (FPVectorial)
JD:
Hi there everyone,
I am using the FPVectorial library to create a Word/ODF document that contains a table with 2 columns. According to the example on this page http://wiki.lazarus.freepascal.org/fpvectorial_-_Text_Document_Support#Simple_Table in the Wiki, a table is created with ONE column by default and to add another column, it is necessary to use AddColWidths.
However, AddColWidths is no longer available!! It looks like the code has been refactored and AddColWidths has been removed.
My code is as shown below:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- AttitudesTable := Page.AddTable; AttitudesTable.PreferredWidth := Dimension(100, dimPercent); AttitudesTable.ColWidthsUnits := dimMillimeter; AttitudesTable.AddColWidths(50); <------ This does not work any more!!!
How can I create a second column in my Attitudes table?
Thanks a lot for your kind assistance.
Cheers,
JD
JD:
Any ideas? Anyone? :D :D
JD:
Alternatively, can one add 2 cells horizontally side by side in the same row?
JD
Mike.Cornflake:
I'm away from code right now, but what happens when you run the example code?
Also - I note you have typed AddColWidths. The call is (or should be) AddColWidth (ie singluar)
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---Table.AddColWidth(50);
UPDATE:
Ug. Looking at the pas file online (https://svn.freepascal.org/svn/lazarus/trunk/components/fpvectorial/fpvectorial.pas), I concur that call is no longer present. No idea who removed it or why :-( It'll be more than a few days before I get a chance to look at this though.
UPDATE2:
It's been more than 4 years since I wrote that code. Looking through docxvectorialwriter.pas.Procedure ProcessTable(ATable: TvTable); ColWidths is optional. It's sufficient to add Cells to a row to determine column count.
Reading the comments on the wiki - looks like ColWidths is ONLY essential if you're merging cells AND writing to ODT.
All I can suggest is you try, and in a few days I'll try and understand if a change has been made and why.
JD:
@Mike.Cornflake
Thank you very much for your reply. I was getting desperate. :D
I looked at the code for TvTable. It is defined as follows:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- (* Note on the grid used for the table For the table shown below, three ColWidths must be defined. First row should only have 2 cells. First cell spans 2 columns. Second row should only have 2 cells. Second cell spans 2 columns. Third row should have 3 cells. Each cell only spans 1 column (default) X,Y +-----+------+---------+ | | | +-----+----------------+ | | | +-----+------+---------+ | | | | +-----+------+---------+ The table draws at X,Y and downwards *) // TvTable.Style should be a Table Style, not a Paragraph Style // and is optional. TvTable = class(TvEntityWithStyle) private Rows: TFPList; ColWidthsInMM: array of Double; // calculated during Render TableWidth, TableHeight: Double; // in mm; calculated during Render procedure CalculateColWidths(constref ARenderInfo: TvRenderInfo); procedure CalculateRowHeights(constref ARenderInfo: TvRenderInfo); public ColWidths: array of Double; // Can be left empty for simple tables // MUST be fully defined for merging cells ColWidthsUnits : TvUnits; // Cannot mix ColWidth Units. Borders : TvTableBorders; // Defaults: single/black/inside and out PreferredWidth : TvDimension; // Optional. Units mm. SpacingBetweenCells: Double; // Units mm. Gap between Cells. CellSpacingLeft, CellSpacingRight, CellSpacingTop, CellSpacingBottom: Double; // space around each side of cells, in mm BackgroundColor : TFPColor; // Optional. constructor create(APage : TvPage); override; destructor destroy; override; function AddRow: TvTableRow; function GetRowCount : Integer; function GetRow(AIndex: Integer) : TvTableRow; // function GetColCount(): Integer; // procedure Render(var ARenderInfo: TvRenderInfo; ADoDraw: Boolean = True); override; function GenerateDebugTree(ADestRoutine: TvDebugAddItemProc; APageItem: Pointer): Pointer; override; end;
There does not seem to be any way to add several columns to a table.
By the way, I must congratulate the authors of fpvectorial because it produces perfect Microsoft Word documents.
I was pleasantly surprised. I just need to be able to create multi-columned tables in those Word documents.
Cheers,
JD
Navigation
[0] Message Index
[#] Next page