Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Wed May 03, 2017 7:42 am

Hello,
I have a document with a header part and some tables.
I'm not able to position the first table exactly,
changing the vertrelationto the reesult does not change.
If I specificate a small vertical position (es. 0 or 10) it overwrites the header,
If I specificate a large vertical position (es. 50) it is too far from the header.
I can't find an intermediate value for the vertical position to p place as soon after the header as possible (which means almost attached).
I attach my code and the result,
if anyone can help me.

The third document I've attached (m33484_20170308_148), shows the table 'tblNote', in case it contains 5 rows, the 5th does not appear and the second page which should contain it is not created.

thank you
Paola

paolagumi
 
Posts: 81
Joined: Tue Apr 21, 2015 11:32 am

Wed May 03, 2017 10:33 am

Hello,

Thanks for your inquiry.
What does the first table refer to? Is the first table in the body part ?
Besides, in order to help us with a better investigation, could you also upload the created word document?

Many Thanks,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Wed May 03, 2017 11:05 am

Hi Jane,
yes, I mean the first table in the section body part, after the header.
Here attached you see the document, it's a pdf.

best regards,
Paola

paolagumi
 
Posts: 81
Joined: Tue Apr 21, 2015 11:32 am

Thu May 04, 2017 10:31 am

Hello,

Thanks for your document.
After investigation, we find the issue lies on the text wrapping. In Word, if you apply some text wrapping style, the related height will be omitted, and since the table can't be located, it' hard to set the intermediate value. We sugget you create a textbox which can be positioned in the header and put the table(the table in the header) into it. Then, do not set the text wrapping of the table in the body. After these operations, the table in the body will be automaticaly after the header.
Code for reference;
Code: Select all
Dim tb As Spire.Doc.Fields.TextBox = ParHdr.AppendTextBox(150, 34)
tb.Format.TextWrappingStyle = TextWrappingStyle.Square
tb.Format.HorizontalPosition = 420
tb.Format.VerticalPosition = 60
Dim tblAgenti As Table = tb.Body.AddTable(True)
tblAgenti.ResetCells(2, 2)

For i As Integer = 0 To 1
   For j As Integer = 0 To 1
      tblAgenti.Rows(i).Cells(j).Width = 20
      tblAgenti.Rows(i).Cells(j).AddParagraph().AppendText("15321345")
   Next
Next

Dim tblNote As Table = SezMacroCedola.Body.AddTable(True)
tblNote.TableFormat.LayoutType = LayoutType.Fixed
tblNote.ResetCells(50, 10)
For k As Integer = 0 To 49
   For m As Integer = 0 To 9
      tblNote.Rows(k).Cells(m).Width = 60
      tblNote.Rows(k).Cells(m).AddParagraph().AppendText(k + "+" + m)
   Next
Next

MacroCedola.SaveToFile("10462.docx", FileFormat.Docx)
MacroCedola.SaveToFile("10462.pdf", FileFormat.PDF)

Concerning the second issue(the 5th row missing), I'm still a little confused, could you share us with the word file you get(like the code I provide, you can save the file to docx first)? And also, provide the related code snippet to help us reproduce the issue.
If there's still any doubt about the first issue, please tell us.

Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Thu May 04, 2017 12:26 pm

Hello Jane,
thank you for your answer to my issue.
The suggestion to create a textbox, put it in the in the header at a precise position and put the table(the table in the header) into it, is correct. Then I removed the wrapping styles.
It works fine, the table in the body is soon after the header....in the first page,
but not in the second.
I'm attaching the code and the .pdf,
if you can help me again.

For the second issue (5th row missing), I'll save it as a docx and send it to you.

Sincerely,
Paola

paolagumi
 
Posts: 81
Joined: Tue Apr 21, 2015 11:32 am

Thu May 04, 2017 12:34 pm

hello Jane,
here you see attached the .docx file, with the 5th row in the table 'tblNote', which in the .pdf is not visible.
Thank you in advance,

Sincerely,
Paola

paolagumi
 
Posts: 81
Joined: Tue Apr 21, 2015 11:32 am

Fri May 05, 2017 2:35 am

Hello,

Strangely, both of the two issue you mentioned did not occur on my side, and I attched my whole testing code and the result documents for your checking. Hope it helps.
Code: Select all
Dim MacroCedola As New Document()

'Definisce tutti i font utilizzati nel documento:
Dim fUniversBold12 As New Spire.Doc.Formatting.CharacterFormat(MacroCedola)
Dim _with1 = fUniversBold12
_with1.FontName = "Univers"
_with1.FontSize = 11
_with1.Bold = True

Dim fUniversBold7 As New Spire.Doc.Formatting.CharacterFormat(MacroCedola)
Dim _with2 = fUniversBold7
_with2.FontName = "Univers"
_with2.FontSize = 7
_with2.Bold = True

Dim fCourier8 As New Spire.Doc.Formatting.CharacterFormat(MacroCedola)
Dim _with3 = fCourier8
_with3.FontName = "Courier New"
_with3.FontSize = 8
_with3.Bold = True

Dim fCourier7 As New Spire.Doc.Formatting.CharacterFormat(MacroCedola)
Dim _with4 = fCourier7
_with4.FontName = "Courier New"
_with4.FontSize = 7
_with4.Bold = True

Dim fCourier10 As New Spire.Doc.Formatting.CharacterFormat(MacroCedola)
Dim _with5 = fCourier10
_with5.FontName = "Courier New"
_with5.FontSize = 10
_with5.Bold = True

Dim fCourier9 As New Spire.Doc.Formatting.CharacterFormat(MacroCedola)
Dim _with6 = fCourier9
_with6.FontName = "Courier New"
_with6.FontSize = 9
_with6.Bold = True

Dim fUniversBold6 As New Spire.Doc.Formatting.CharacterFormat(MacroCedola)
Dim _with7 = fUniversBold6
_with7.FontName = "Univers"
_with7.FontSize = 6
_with7.Bold = True

Dim fUniversBold55 As New Spire.Doc.Formatting.CharacterFormat(MacroCedola)
Dim _with8 = fUniversBold55
_with8.FontName = "Univers"
_with8.FontSize = 5.5F
_with8.Bold = True

Dim fTbBianco As New Spire.Doc.Formatting.TextBoxFormat()
Dim _with9 = fTbBianco
_with9.LineColor = Color.White
_with9.FillColor = Color.White

Dim fTbGrigio As New Spire.Doc.Formatting.TextBoxFormat()
Dim _with10 = fTbGrigio
_with10.FillColor = Color.LightGray
_with10.LineColor = Color.Black

Dim SezMacroCedola As Section = MacroCedola.AddSection()

Dim _with11 = (SezMacroCedola.PageSetup)
_with11.PageSize = PageSize.A4
_with11.Orientation = PageOrientation.Landscape
_with11.Margins.Top = 0
_with11.Margins.Bottom = 5F
_with11.Margins.Left = 6F
_with11.Margins.Right = 0F

' da Amy Zhao:
Dim stileCour8 As New ParagraphStyle(MacroCedola)
stileCour8.Name = "stileCourier8Mio"
stileCour8.CharacterFormat.FontName = "Courier New"
stileCour8.CharacterFormat.FontSize = 8
stileCour8.CharacterFormat.Bold = True
MacroCedola.Styles.Add(stileCour8)
' fine

Dim stileUniversBold55 As New ParagraphStyle(MacroCedola)
stileUniversBold55.Name = "stileUniversBold55Mio"
stileUniversBold55.CharacterFormat.FontName = "Univers"
stileUniversBold55.CharacterFormat.FontSize = 5.5F
stileUniversBold55.CharacterFormat.Bold = True
MacroCedola.Styles.Add(stileUniversBold55)

Dim stileUniversBold6 As New ParagraphStyle(MacroCedola)
stileUniversBold6.Name = "stileUniversBold6Mio"
stileUniversBold6.CharacterFormat.FontName = "Univers"
stileUniversBold6.CharacterFormat.FontSize = 6
stileUniversBold6.CharacterFormat.Bold = True
MacroCedola.Styles.Add(stileUniversBold6)

Dim stileUniversBold7 As New ParagraphStyle(MacroCedola)
stileUniversBold7.Name = "stileUniversBold7Mio"
stileUniversBold7.CharacterFormat.FontName = "Univers"
stileUniversBold7.CharacterFormat.FontSize = 7
stileUniversBold7.CharacterFormat.Bold = True
MacroCedola.Styles.Add(stileUniversBold7)

'------------------------------------------------------------------------------------
' Fondo pagina MacroCedola: Pagine numero di pagine totali

SezMacroCedola.PageSetup.Borders.Top.Space = 20
MacroCedola.Sections(0).PageSetup.Borders.Top.Space = 5
' la stessa cosa

SezMacroCedola.PageSetup.PageBorderIncludeHeader = False
SezMacroCedola.PageSetup.HeaderDistance = 10


'------------------------------------------------------------------------------------
' Intestazione MacroCedola: Progressivo, Data, Orari inizio e fine, Bacino

Dim hdr As Spire.Doc.HeaderFooter = MacroCedola.Sections(0).HeadersFooters.Header
Dim ParHdr As Paragraph = hdr.AddParagraph()

'Dim ParIntestazione As Paragraph = SezMacroCedola.AddParagraph()
ParHdr.AppendPicture(Image.FromFile("C:\Users\Administrator\Pictures\1.gif")).VerticalPosition = 1
ParHdr.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Left

Dim tbTitolo As Spire.Doc.Fields.TextBox = ParHdr.AppendTextBox(1000, 20)
Dim parTitolo As Paragraph = tbTitolo.Body.AddParagraph()
parTitolo.AppendText("MACRO CEDOLA VERIFICA TITOLI DI VIAGGIO").ApplyCharacterFormat(fUniversBold12)
tbTitolo.Format.HorizontalPosition = 100
tbTitolo.Format.VerticalPosition = 0.5F
tbTitolo.Format.LineColor = Color.White
tbTitolo.Format.FillColor = Color.White

Dim tbProgressivoData As Spire.Doc.Fields.TextBox = ParHdr.AppendTextBox(1000, 20)
Dim parProgressivoData As Paragraph = tbProgressivoData.Body.AddParagraph()
parProgressivoData.AppendText("PROGRESSIVO:" + "2222").ApplyCharacterFormat(fUniversBold7)
tbProgressivoData.Format.HorizontalPosition = 440
tbProgressivoData.Format.VerticalPosition = 0.5F
tbProgressivoData.Format.LineColor = Color.White
tbProgressivoData.Format.FillColor = Color.White

Dim tbProgressivo As Spire.Doc.Fields.TextBox = ParHdr.AppendTextBox(50, 15)
Dim parProgressivo As Paragraph = tbProgressivo.Body.AddParagraph()
parProgressivo.AppendText("152").ApplyCharacterFormat(fCourier8)
tbProgressivo.Format.HorizontalPosition = 510
tbProgressivo.Format.VerticalPosition = 0.5F
tbProgressivo.Format.LineColor = Color.Black
tbProgressivo.Format.FillColor = Color.LightGray

Dim tbData As Spire.Doc.Fields.TextBox = ParHdr.AppendTextBox(65, 15)
Dim parData As Paragraph = tbData.Body.AddParagraph()
parData.AppendText("2017.5.3").ApplyCharacterFormat(fCourier8)
tbData.Format.HorizontalPosition = 605
tbData.Format.VerticalPosition = 0.5F
tbData.Format.LineColor = Color.Black
tbData.Format.FillColor = Color.LightGray

Dim tbAzienda As Spire.Doc.Fields.TextBox = ParHdr.AppendTextBox(50, 15)
Dim parAzienda As Paragraph = tbAzienda.Body.AddParagraph()
parAzienda.AppendText("TPER").ApplyCharacterFormat(fCourier8)
tbAzienda.Format.HorizontalPosition = 740
tbAzienda.Format.VerticalPosition = 0.5F
tbAzienda.Format.LineColor = Color.Black
tbAzienda.Format.FillColor = Color.LightGray

'------------------------------------------------------------------------------------
Dim tbTestataCedola0 As Spire.Doc.Fields.TextBox = ParHdr.AppendTextBox(1000, 15)
Dim parTestataCedola0 As Paragraph = tbTestataCedola0.Body.AddParagraph()
parTestataCedola0.AppendText("DATA E ORA INIZIO CEDOLA:").ApplyCharacterFormat(fUniversBold7)
parTestataCedola0.Format.AfterSpacing = 0
tbTestataCedola0.Format.HorizontalPosition = 100
tbTestataCedola0.Format.VerticalPosition = 20
tbTestataCedola0.Format.LineColor = Color.White
tbTestataCedola0.Format.FillColor = Color.White

Dim tbDataOraInizioCedola As Spire.Doc.Fields.TextBox = ParHdr.AppendTextBox(105, 15)
Dim parDataOraInizioCedola As Paragraph = tbDataOraInizioCedola.Body.AddParagraph()
parDataOraInizioCedola.AppendText("2017.5.3 17:23").ApplyCharacterFormat(fCourier8)
tbDataOraInizioCedola.Format.HorizontalPosition = 210
tbDataOraInizioCedola.Format.VerticalPosition = 20
tbDataOraInizioCedola.Format.LineColor = Color.Black
tbDataOraInizioCedola.Format.FillColor = Color.LightGray

Dim tbBacino As Spire.Doc.Fields.TextBox = ParHdr.AppendTextBox(120, 15)
Dim parBacino As Paragraph = tbBacino.Body.AddParagraph()
parBacino.AppendText("aaaa").ApplyCharacterFormat(fCourier8)
tbBacino.Format.HorizontalPosition = 605
tbBacino.Format.VerticalPosition = 20
tbBacino.Format.LineColor = Color.Black
tbBacino.Format.FillColor = Color.LightGray

Dim tbPagina As Spire.Doc.Fields.TextBox = ParHdr.AppendTextBox(50, 18)
' altezza era 15
tbPagina.Format.HorizontalPosition = 775
tbPagina.Format.VerticalPosition = 17
'era 20
tbPagina.Format.LineColor = Color.Black
tbPagina.Format.FillColor = Color.LightGray

'Dim NumeroPagina As Int32 = Spire.Doc.FieldType.FieldPage
'Dim PagineTotali As Int32 = Spire.Doc.FieldType.FieldNumPages
'Dim parPagina As Paragraph = tbPagina.Body.AddParagraph()
'parPagina.AppendText(NumeroPagina & " /" & PagineTotali).ApplyCharacterFormat(fCourier8)
'parPagina.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Center
'parPagina.Format.Borders.Space = 0
'parPagina.Format.AfterSpacing = 0
'parPagina.Format.BeforeSpacing = 0

Dim parPagina As Paragraph = tbPagina.Body.AddParagraph()
parPagina.AppendField("", FieldType.FieldPage).ApplyCharacterFormat(fCourier8)
parPagina.AppendText("/").ApplyCharacterFormat(fCourier8)
parPagina.AppendField("", FieldType.FieldNumPages).ApplyCharacterFormat(fCourier8)
parPagina.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Center
parPagina.Format.Borders.Space = 0
parPagina.Format.AfterSpacing = 0
parPagina.Format.BeforeSpacing = 0

Dim tbTestaDtOraInizioFine As Spire.Doc.Fields.TextBox = ParHdr.AppendTextBox(300, 15)
Dim parTestaDtOraInFinCedola As Paragraph = tbTestaDtOraInizioFine.Body.AddParagraph()
parTestaDtOraInFinCedola.AppendText("DATA E ORA FINE   CEDOLA:").ApplyCharacterFormat(fUniversBold7)
parTestaDtOraInFinCedola.Format.AfterSpacing = 0
tbTestaDtOraInizioFine.Format.HorizontalPosition = 100
tbTestaDtOraInizioFine.Format.VerticalPosition = 40
tbTestaDtOraInizioFine.Format.LineColor = Color.White
tbTestaDtOraInizioFine.Format.FillColor = Color.White

Dim tbDataOraFineCedola As Spire.Doc.Fields.TextBox = ParHdr.AppendTextBox(130, 15)
Dim parDataOraFineCedola As Paragraph = tbDataOraFineCedola.Body.AddParagraph()
parDataOraFineCedola.AppendText("2017.5.3 17:23").ApplyCharacterFormat(fCourier8)
tbDataOraFineCedola.Format.HorizontalPosition = 210
tbDataOraFineCedola.Format.VerticalPosition = 40
tbDataOraFineCedola.Format.LineColor = Color.Black
tbDataOraFineCedola.Format.FillColor = Color.LightGray


'table in the header
Dim tb As Spire.Doc.Fields.TextBox = ParHdr.AppendTextBox(100, 34)
tb.Format.NoLine = True
tb.Format.TextWrappingStyle = TextWrappingStyle.Square
tb.Format.HorizontalPosition = 420
tb.Format.VerticalPosition = 60
Dim tblAgenti As Table = tb.Body.AddTable(True)
tblAgenti.ResetCells(2, 2)

For i As Integer = 0 To 1
   For j As Integer = 0 To 1
      tblAgenti.Rows(i).Cells(j).Width = 40
      tblAgenti.Rows(i).Cells(j).AddParagraph().AppendText("1534")
   Next
Next
'first table in the body
Dim tblNote As Table = SezMacroCedola.Body.AddTable(True)
tblNote.TableFormat.Positioning.DistanceFromTop = 3
tblNote.TableFormat.LayoutType = LayoutType.Fixed
tblNote.ResetCells(5, 10)
For k As Integer = 0 To 4
   For m As Integer = 0 To 9
      tblNote.Rows(k).Cells(m).Width = 60
      tblNote.Rows(k).Cells(m).AddParagraph().AppendText(k + "+" + m)
   Next
Next
'2nd table in the body
SezMacroCedola.AddParagraph().AppendText("table2")
Dim tblNote1 As Table = SezMacroCedola.Body.AddTable(True)
tblNote1.TableFormat.LayoutType = LayoutType.Fixed
tblNote1.ResetCells(5, 10)
For k As Integer = 0 To 4
   For m As Integer = 0 To 9
      tblNote1.Rows(k).Cells(m).Width = 60
      tblNote1.Rows(k).Cells(m).AddParagraph().AppendText(k + "+" + m)
   Next
Next
'3rd table in the body
SezMacroCedola.AddParagraph().AppendText("table2")
Dim tblNote2 As Table = SezMacroCedola.Body.AddTable(True)
tblNote2.TableFormat.LayoutType = LayoutType.Fixed
tblNote2.ResetCells(30, 10)
For k As Integer = 0 To 29
   For m As Integer = 0 To 9
      tblNote2.Rows(k).Cells(m).Width = 60
      tblNote2.Rows(k).Cells(m).AddParagraph().AppendText(k + "+" + m)
   Next
Next


MacroCedola.SaveToFile("10462.docx", FileFormat.Docx)
MacroCedola.SaveToFile("10462.pdf", FileFormat.PDF)


Please simplify your project and refer to my code to see if the issues still exist. Also, if there's still no progress, just send the result word and pdf file to us. Please note, to help us find a solution quickly, we need the result files generated by your project which could show the issue rather than the files you expected.

Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Fri May 05, 2017 7:42 am

Hello Jane,
modyfing the code in the way you suggsted me, the result doen not change, it's even worse: the fisrt table in the body (tblCorse) in the first page overwrites the header.
I'm sending you attached my code, the result documents in pdf and docx formats.
best regards,
Paola

paolagumi
 
Posts: 81
Joined: Tue Apr 21, 2015 11:32 am

Fri May 05, 2017 9:06 am

Hello,

I checked your code and found you have commented out the text wrapping style of the table in the header. Please uncomment this line:
Code: Select all
'tbAgenti.Format.TextWrappingStyle = Spire.Doc.Documents.TextWrappingStyle.Square


Many Thanks,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Fri May 05, 2017 12:27 pm

Ok, I have discommented the line, now it works,
i the two pages the header and the fisrt table are at the same position,
but the table is too much below the header, I'll try again.

best regards,
Paola

paolagumi
 
Posts: 81
Joined: Tue Apr 21, 2015 11:32 am

Mon May 08, 2017 1:37 am

Hello,

Sorry for the late reply as weekend.
How is the issue now? If the table is too much below the header, you could try to modify the value of the property "tblCorse.TableFormat.Positioning.DistanceFromTop" to be smaller.
I'm looking forward to your feedback.

Sincerely,
Jane
E-icebluie support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Mon May 08, 2017 7:09 am

Hello Jane,
setting the property:
"tblCorse.TableFormat.Positioning.DistanceFromTop" , to a small value (e.g. 5) or to a large one (e.g. 150), the result doesn not change and the tblCorse is placed at ZERO distance from the top.

setting the property:
"tblCorse.TableFormat.Positioning.VertPosition" e.g. to 35, it is too far from the header,
setting it to 35, it is overwritten on the header.
I can't set an intermediate value.

Please, let me know what I can do to solve it,
best regards,
Paola

paolagumi
 
Posts: 81
Joined: Tue Apr 21, 2015 11:32 am

Mon May 08, 2017 10:02 am

Dear Paola,

First, please kindly note when you set the "tblCorse.TableFormat.Positioning.VertPosition", the first table will automatically apply the text wrapping style, this is the reason why you got the header overwritten. You can confirm it in the docx file you generated. Besides, the "tblCorse.TableFormat.Positioning.DistanceFromTop" only takes effect when a text wrapping style is applied, and I apologize for my mistake on this point.
Concerning your case, how about adding a transparent textbox after the table in the header to increase the height so that it looks like there's a distance between the header and the first table?
The code:
Code: Select all
 
Dim tb1 As Spire.Doc.Fields.TextBox = ParHdr.AppendTextBox(150, 34)
'tb.Format.NoLine = true;
tb1.Format.FillColor = Color.Transparent
tb1.Format.LineColor = Color.Transparent
tb1.Format.TextWrappingStyle = TextWrappingStyle.Square
tb1.Format.HorizontalPosition = 420
tb1.Format.VerticalPosition = 94
'you need to modify the data according to your situation'

In addition, you can also try to put the tables in the body part into textboxs like the table in the header. In this case, the position can be located, howerver, it is a little bit cumbersome.
Hope the answer helps.

Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Mon May 08, 2017 12:44 pm

Hello Jane,
adding a transparent textbox after the table in the header to increase the height, has no results:
the table tblCorse in the body is still overwritten on the header, even if I increase the vertical position of the transparent textbox.

Putting the tables in the body part into textboxs is a problem for me, because I don't know in advance the height of the table.

Let mw know when you can,

thanks,
sincerely,
Paola

paolagumi
 
Posts: 81
Joined: Tue Apr 21, 2015 11:32 am

Tue May 09, 2017 1:22 am

Hello Paola,

When you apply the transparent texbox in the header, you need to comment out the property
"tblCorse.TableFormat.Positioning.VertPosition" to avoid the automatic text wrapping of the first table in the body, have you done that?

Sincerely,
Jane
E--iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Return to Spire.Doc