Free Support Forum - aspose.com

Mark table rows as header rows (for the styling) while not having the header repeat

Hi,

I am trying to build a table that has multiple header rows. I apply the table style to the whole table. By using the RowFormat.HeadingFormat = true I achieve that the header rows are all styled correctly as header style but unfortunately this settting also makes the header repeat itself which I don't want in this context.

It works if there is only one header row, the first one allways gets the header styling but if I have more than one it does not; I have to be able to mark them somehow as header rows. It almost seems like I need 2 setttings: the one that tells aspose that this is a header row and another for the repeat, but I couldn't find anything that does the trick.

How can I tell aspose that my rows are header rows and need to apply the table header styling without the repeat header side effect?
Thanks a lot!

Maria

Hi Maria,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry.

Sorry for the inconvenience faced. Unfortunately, it’s difficult to suggest anything without having looked into your documents. Could you please share the sample input and output document? So we will have close look into the documents and suggest you solution accordingly.

Please feel free to contact us for any further assistance.

Best Regards,

Hi Tilal,

thanks for your response. It seems that there is no elegant and easy way to mark those header rows as such without having the repetition over the pages. So my next course of action is to try to take all the styling features of the defined table style first row ( the table style comes from a template and it has a different first row definition - this is why if I only have one row even if I don't apply the HeadingFormat=true the row will be styled properly) and apply it to all my rows in the multi-row header that I am creating.

So could I get the table style of the first row as a whole so I can aplly it to every row I need to? Something like getFirstRowStyle?

If I cannot take it all, do you know how to get them one by one from the first row and what are all the styling settings that I will need to apply one by one to make the 2.nd row look like the the first?

All I need to do is what happens behind the scenes when I apply the HeadingFormat=true to a row, all but the repetition on every page part.

Thanks for helping,

Maria

Hi Maria,


Thanks for your inquiry.

From what I can gather you are applying a table style to a table, and setting the table options to display different formatting from the table style for the heading rows. However to do this you are using the option repeat as header row for multiple rows which does display the style but also repeats the header row if the table is more than a page long. Is this correct?

If this is the case then that is the expected behavior of a Microsoft word document, the table styles in combination with the header rows are suppose to work in that way.

To achieve what you are looking for you may wish to copy the the formatting of the header row and use it for the next rows instead of enabling the repeat as header row switch. To achieve this you must first expand the table styles to direct formatting and then clone the row and insert it below the original. The formatting must be expanded so it is copied when cloned.

See the following code below for a demonstration.

// Retrieve the first table in the document.<o:p></o:p>

Table table = (Table)doc.GetChild(NodeType.Table, 0, true);<o:p></o:p>

// Call this method to expand formatting from table styles onto runs and paragraphs.<o:p></o:p>

doc.ExpandTableStylesToDirectFormatting();

// Clone the header row of the table.<o:p></o:p>

Row clonedRow = (Row)table.FirstRow.Clone(true);<o:p></o:p>

// Remove all content from the cloned row’s cells. This makes the row ready for<o:p></o:p>

// new content to be inserted into.<o:p></o:p>

foreach (Cell cell in clonedRow.Cells)<o:p></o:p>

cell.RemoveAllChildren();<o:p></o:p>

// Insert the row after the first row.<o:p></o:p>

table.InsertAfter(clonedRow, table.FirstRow);


Please let me know if there are any problems.

Thanks,

Thanks Adam,

yes you understand correctly. I need to take the first row table style and apply it to all the rows in my header. I tried your approach but it seems that I cannot simply clone the first row as I have merged cells in each row (this is why it is a multi-row header) I even tried with a dummy row that would contain all the pre-merged state cells but then the merging does not work.
I attached a screenshot of the header with the HeadingFormat true and false option

So the question is if I expand the style and take the styling of the row one by one, what are all the things I care about? Is there somewhere a list of all the styling options that can be defined in the table styling? I couldn’t find one and since I don’t know what the styling of that header is going to be; I need them all addressed.

Also I have the problem someone else had here in forum too with the border of the repeated header missing in the first column. (3.rd image - same header as the second but on the next page). Is there some new knowledge about that?

Thanks for helping!

Hi Maria,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for the inquiry. Please refer to following articles regarding your table styles query. Hopefully it would serve the purpose.

http://www.aspose.com/docs/display/wordsnet/Working+with+Table+Styles

http://www.aspose.com/docs/display/wordsnet/Style+Members

Furthermore, in reference to your second question about missing border, Could you please share the sample input and output document. So we could reproduce the issue at our side and suggest you accordingly. Please note sharing documents here are safe as only Aspose staff and the thread owner has access over these shared documents.

Please feel free to contact us for any further assistance.

Best Regards,

The input doc is a blank one, the output has the table based on the Table Grid 3 styling, but it does the same with every styling. Both are attached.

It seems to be a word problem and it has something to do with the fact that the fist column has vertically merged cells but so does the second and it still draws the line at the bottom of the header. Interesting enough as I looked at it zoomed to view all the pages at once, the second merged column looses the line too in 2 of the 3 repeated header pages. In a normal one page zoom the second merged column shows the line in all of the repeated headers, the first never does.

Not sure if there is some aspose solution to avoid this but it would be nice if the header would repeat itself completly with all the borders defined.

Thanks,

Maria

Hi Maria,

Sorry for the inconvenience faced. I am working over your query and will update you soon.

Best Regards,

Hi Maria,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your patience. I have tested multi rows header table; with/without repeat header option. But unfortunately, I couldn’t find the border lost issue. For further investigation, we will appreciate if you please share the sample code? So we look into the issue at our side and suggest you accordingly.

Sorry for the inconvenience faced.

Best Regards,

Hi Tilal,

so you tested an inserted table with a multi row header AND vertically merged cells in the first column of the body and you didn't have the problem? I put together a quick test and it happens allways when I have the merged cells, see screenshot.

         
  Table wordTable = _docBld.StartTable();
_docBld.RowFormat.HeadingFormat = true;
for (int c = 0; c < 10; c++)
{
_docBld.InsertCell();
wordTable.StyleName = wordTableSpec.TableStyle;
_docBld.Write("text");
}
_docBld.EndRow();
for (int c = 0; c < 10; c++)
{
_docBld.InsertCell();
_docBld.Write("text");
}
_docBld.EndRow();

for (int r = 0; r < 100; r++)
{
for (int c = 0; c < 10; c++)
{
Cell crtCell = _docBld.InsertCell();

if (c < 5)
{
if (r == 0)
{
crtCell.CellFormat.VerticalMerge = CellMerge.First;
_docBld.RowFormat.HeadingFormat = false;
}
else
{
crtCell.CellFormat.VerticalMerge = CellMerge.Previous;
}
}
else
{
crtCell.CellFormat.VerticalMerge = CellMerge.None;
}
_docBld.Write("text");
}
_docBld.EndRow();
}
wordTable.AutoFit(AutoFitBehavior.AutoFitToContents);
wordTable.StyleOptions = TableStyleOptions.Default | TableStyleOptions.RowBands;
_docBld.EndTable();

<?xml:namespace prefix = o ns = “urn:schemas-microsoft-com:office:office” /><o:p>

Hi Maria,

Thanks for the additional information. Could you please share complete sample code as definition of “wordTableSpec” object is missing in code and confirm your Aspose.Words API version also?

wordTable.StyleName = wordTableSpec.TableStyle;

Moreover, there is another issue in cell merging code. Please note while merging cells in a table, the cells are going to be merged with first cell should be empty i.e. cells having CellMerge property set to Previous. So please don’t assign any text to cells having CellMerge property set to Previous. Otherwise while you resize any column in your output document the merging will be lost, as happening in current case.

Please check following amended code. Please also refer to the following article for more information.

http://www.aspose.com/docs/display/wordsjava/Working+with+Merged+Cells

if (c < 5)

{

if (r == 0)

{

crtCell.CellFormat.VerticalMerge = CellMerge.First;

_docBld.RowFormat.HeadingFormat = false;

_docBld.Write("text");

}

else

{

crtCell.CellFormat.VerticalMerge = CellMerge.Previous;

}

}

else

{

crtCell.CellFormat.VerticalMerge = CellMerge.None;

_docBld.Write("text");

}

Please feel free to contact us for any further assistance.

Best Regards,

Hi Tilal,

thanks for the hints, however the text added to all the merged cells is not the issue here, I put the code together quick and didn’t see that. Also the name of the style can be say “Grid Table 4”. After changing both those things in the code it still happens… Also try to zoom down to 2 pages or less. If it does not happen for you it may be the word version. I use the latest aspose libs and word2007. Please let me know if you are able to reproduce it or not.
Thanks,
Maria

Hi Maria,

Sorry for the inconvenience faced. While using the latest version of Aspose.Words i.e. v11.6.0, I have managed to reproduce this issue on my side. I have logged the issue in our bug tracking system, the issue ID is WORDSNET-6712. I have linked your request to this issue and you will be notified as soon as it is resolved.

Please feel free to contact us for any further assistance.

Best Regards,

/* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-qformat:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin:0in; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:"Times New Roman"; mso-fareast-theme-font:minor-fareast; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi;}

<![endif]–>

The issues you have found earlier (filed as WORDSNET-6712) have been fixed in this .NET update and this Java update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.