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.

Tue May 09, 2017 7:21 am

Hello Jane,
yes, I discommented it.

If I place your transparent textbox in the header,
the table in the body does not move at all, in both cases (with or without the transparent textbox):

with vertical position 35, the tblCorse table is too far from the header,

with vertical position 34 (I wrote badly in my previous message, excuse me),
the tblCorse table is overwritten in the header.

I wait for you answer,
thank you,
Paola

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

Tue May 09, 2017 8:08 am

Dear Paola,

Thanks for your answer.
Strangely, everything works well at my end. Please see my entire code as well as the result docx file and pdf file in the attachment.
Code: Select all
'Definisce tutti i font utilizzati nel documento:
'style information
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
' add a transparent textbox to increase the height of the header
Dim tb1 As Spire.Doc.Fields.TextBox = ParHdr.AppendTextBox(150, 10)
' you can modify the height accordingly
'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

'first table in the body
Dim tblNote As Table = SezMacroCedola.Body.AddTable(True)
tblNote.TableFormat.LayoutType = LayoutType.Fixed
'tblNote.TableFormat.Positioning.VertPosition = 30;
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.TableFormat.Positioning.VertRelationTo = VerticalRelation.Margin;
'tblNote1.TableFormat.Positioning.VertPosition = 55;
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("table3")
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)

How about trying my code snippet? See if the result is the same as mine.
Looking forward to your feedback.

Sincerely,
Jane
E-iceblue support team
Last edited by Jane.Bai on Tue May 09, 2017 8:39 am, edited 1 time in total.
User avatar

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

Tue May 09, 2017 8:17 am

Dear Jane,

the space between the header and the body, in your documents, is too large:
Can you try to change it, so that it results about 2-3 distance from the header, and not too far (with the transparent textbox) or overwritten?

Please, see attached my code and the results, in pdf and docx.

Please let me know,
thank you,
Paola

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

Tue May 09, 2017 10:19 am

Dear Paolo,

I will look into the code and documents you provided just now and give you the reply tomorrow.
Besides, I find a much easier way, you don't need to add a transparent textbox, increasing the height of the textbox in the header will also acheive the same target.
Code: Select all
 Dim tbAgenti As Spire.Doc.Fields.TextBox = ParHdr.AppendTextBox(400, 40)'change the height accordingly
                tbAgenti.Format.NoLine = True
                tbAgenti.Format.TextWrappingStyle = Spire.Doc.Documents.TextWrappingStyle.Square
                tbAgenti.Format.HorizontalPosition = 415
                tbAgenti.Format.VerticalPosition = 48
                tbAgenti.Format.LineColor = Drawing.Color.White
                tbAgenti.Format.FillColor = Drawing.Color.White
                tbAgenti.Format.InternalMargin.All = 0
                tbAgenti.Format.InternalMargin.Top = 1


Best Wishes,
Jane
E-iceblue support team
Last edited by Jane.Bai on Wed May 10, 2017 1:12 am, edited 1 time in total.
User avatar

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

Tue May 09, 2017 11:58 am

Dear Jane,
thank you for your helpfulness!
I have no hurry, take all the time you need.

sincerely,
Paola

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

Wed May 10, 2017 2:13 am

Hello Paola,

Thanks for sharing your code and result files.
I have made some modifications to your code and added the related code comments which begin with Jane bai, you can search and have a check. In your code, I provided two methods for reaching your desired effect. Since the method 1 is much easier and convenient, I suggest you apply it and comment out method2.
If there's still any problem, just write back to us.

Sincerely,
Jane
E-iceblue support team
User avatar

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

Thu May 11, 2017 1:04 am

Dear Paola,

How is your issue now?
Looking forward to your feedback!

Sincerely,
Jane
E-iceblue support team
User avatar

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

Thu May 11, 2017 11:46 am

Hello Jane,
I'm sorry for writing to you so late...
I didn't have time, here at work.

I'll study and apply your code and solution tomorrow,
then I'll let you know as soon as possible!

Thank you very much,

sincerely
Paola

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

Thu May 11, 2017 12:02 pm

Hello Jane,
I'v ben able to test your code right now,
the tblCorse results overwritten on the header again,
please see the atteched .docx and .pdf documents.

I'm looking forward to you answer,
thank you,

Paola

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

Fri May 12, 2017 2:53 am

Hello Paola,

Thanks for your feedback.
Concerning the case, you need also change the table property of the other tables in the body part, please see the modified code in the attachment.
Just feel free to write back if there's still any issue.

Sincerely,
Jane
E-iceblue support team
User avatar

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

Mon May 15, 2017 8:17 am

Hello Jane,
I'm back at work again,
I've just tested your code:

the first table in the body (tblCorse) is still overwritten on the header,
even increasing the height of the textbox in the header as you did (tbAgenti) from 40 to 43.
Then, I increased more, up to 70, but the result does not change, the header and the first table are still overwritten.

As both using a transparent textbox and increasing the height of the textbox in the header do not work,
what can I do?

thank you,

sincerely,
Paola

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

Mon May 15, 2017 9:47 am

Dear Paola,

Thanks for your feedback again.
After an investigation, we found the issue source. Due to the stimulation data on my side, there's a lack of consideration on a small point. Please see the modified code in attachment.
I apologize for the inconvenience caused.
Hope it works this time. I'm looking forward to your reply.

Sincerely,
Jane
E-iceblue support team
User avatar

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

Mon May 15, 2017 10:23 am

Hi Jane,
your new code works,
but because you commented the line of tblCorse...HorizontalPositioning = 5.
So the table results attached to the left margin, which I don't want!!!
Moreover, the space between the header and the tblCorse is still too large, and it does not reduce if I reduce the height of the table in the header.

If I discomment line of tblCorse...HorizontalPositioning = 5.,
the table tblCorse is again overwritten on the header.

Can you tell me how to set the left margin only for the tables in the body I choose?

There are also three mistakes in you code:
- a line with 'TblCorse(), which I had to delete, it generated an error;
- two lines with SezMacroCedola.SezMacroCedola.AddParagraph: the second string "SezMacroCedola" must be deleted, or it generates an error.

I wait for your answer,
thank you

sincerely,
Paola

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

Mon May 15, 2017 12:44 pm

Hello Jane,
I think it's already last evening-night in China!
So in the meantime, I solved:
1. to leave some space on the left of the table tblCorse, I added this line:
tblCorse.TableFormat.LeftIndent = 10
soon after the line:
tblCorse.TableFormat.LayoutType = LayoutType.Fixed

2. to reduce the space between the header and the first table,
I added these two lines:
tblCorse.ApplyHorizontalMerge(0, 0, tblCorse.Rows(0).Cells.Count - 1)
tblCorse.Rows(0).Height = 2

The second one did not work without merging the other cells.

Thank you very much for everything,
If I should have any more problems, I will tell you.

Thank you again for your precious help,
have a nice day!

sincerely,
Paola

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

Tue May 16, 2017 2:54 am

Hello Paola,

Sorry for the late reply.
Glad to hear that you have solved the issue by yourself.
If there's any problem in the future, please feel free to contact us.

Sincerely,
Jane
E-iceblue support team
User avatar

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

Return to Spire.Doc