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 Oct 17, 2017 11:37 am

I have two line in my database
<p>First</p><p>second</p>

when i export my data into word. It will print in single paragraph.

It should be in two line
First
Second.

NOT like First.Second

Regards
Manish

mvadukul21621
 
Posts: 21
Joined: Thu Mar 29, 2012 7:52 pm

Wed Oct 18, 2017 2:14 am

Dear Manish,

Thanks for your inquiry.
I have tested the scenario with the latest Spire.Doc Pack(hot fix) Version:6.0.21. There are two paragraphs/lines in result document. Here is my testing code:
Code: Select all
            Document doc = new Document();
            Section tmpSection = doc.AddSection();
            Paragraph p = tmpSection.AddParagraph();
            p.AppendHTML("<p>First</p><p>second</p>");
            doc.SaveToFile("11899.docx",FileFormat.Docx);

Please try to use the latest version, if the issue still happens, please share us your complete code for further testing.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Wed Oct 18, 2017 9:16 am

Okay.
Please see below my code. Everything works fine but issue with <p>,</p> not creating paragraph. As you mention in your code use p.AppendHTML("<p>First</p><p>second</p>");

where can i use with my data. Please can you show me. my data coming from this line
data(i1)(j) = StripHTMLTags(dt.Rows(i1)(j).ToString()). Please see in code.

----------------------------------------------------------------------------------------------------
Dim dt As New DataTable()

dt = _sql.GetRiskReport(ProjectName, "IT Risk & Security")


Dim rowCount As Integer = dt.Rows.Count
Dim colCount As Integer = dt.Columns.Count
Dim data As String()() = New String(rowCount - 1)() {}

'Create Table

Dim table As Table = s.AddTable(True)

For i1 As Integer = 0 To rowCount - 1
data(i1) = New String(colCount - 1) {}
For j As Integer = 0 To colCount - 1
data(i1)(j) = StripHTMLTags(dt.Rows(i1)(j).ToString())
Next
Next

'Create Header and Data
Dim Header As String() = {"RAG", "R/I", "Risk / Issue", "Action / Mitigation"}


'Add Cells
table.ResetCells(data.Length + 1, Header.Length)

'Header Row
Dim FRow As TableRow = table.Rows(0)
FRow.IsHeader = True
'Row Height
FRow.Height = 23
'Header Format
FRow.RowFormat.BackColor = Color.AliceBlue
FRow.Cells(0).Width = 50
FRow.Cells(1).Width = 50
FRow.Cells(2).Width = 350
FRow.Cells(3).Width = 350

For i As Integer = 0 To Header.Length - 1
'Cell Alignment
Dim p As Paragraph = FRow.Cells(i).AddParagraph()
FRow.Cells(i).CellFormat.VerticalAlignment = VerticalAlignment.Middle
p.Format.HorizontalAlignment = HorizontalAlignment.Left
'Data Format
Dim TR As TextRange = p.AppendText(Header(i))
TR.CharacterFormat.FontName = "Arial"
TR.CharacterFormat.FontSize = 10
TR.CharacterFormat.Bold = True
Next i

'Data Row
For r As Integer = 0 To data.Length - 1
Dim DataRow As TableRow = table.Rows(r + 1)

'Row Height
DataRow.Height = 20

'C Represents Column.
For c As Integer = 0 To data(r).Length - 1
'Cell Alignment
DataRow.Cells(c).CellFormat.VerticalAlignment = VerticalAlignment.Middle
'Fill Data in Rows
Dim p2 As Paragraph = DataRow.Cells(c).AddParagraph()
Dim TR2 As TextRange = p2.AppendText(data(r)(c))
'Format Cells
p2.Format.HorizontalAlignment = HorizontalAlignment.Left
TR2.CharacterFormat.FontName = "Arial"
TR2.CharacterFormat.FontSize = 10

DataRow.Cells(0).Width = 50
DataRow.Cells(1).Width = 50
DataRow.Cells(2).Width = 350
DataRow.Cells(3).Width = 350



If dt.Rows(r)(c).ToString() = "Green" Then
DataRow.Cells(0).CellFormat.BackColor = Color.Green
ElseIf dt.Rows(r)(c).ToString() = "Amber" Then
DataRow.Cells(0).CellFormat.BackColor = Color.Orange
ElseIf dt.Rows(r)(c).ToString() = "Red" Then
DataRow.Cells(0).CellFormat.BackColor = Color.Red
End If

Next c
Next r


------------------------------------------------------------------------------------

mvadukul21621
 
Posts: 21
Joined: Thu Mar 29, 2012 7:52 pm

Wed Oct 18, 2017 9:56 am

Dear mvadukul21621,

Thanks for your feedback.
I checked your code in email, and found the custom method StripHTMLTags. Then I created a datatable as below.
Code: Select all
            DataTable dt = new DataTable();
            dt.Columns.Add("data", typeof(string));
            DataRow row = dt.NewRow();
            row[0] = "<p>first</p><p>second</p>";
            dt.Rows.Add(row);

I found the issue is not caused by our product, it is because the data you have is just one line, please check the screenshot.
In addition, there is no need to replace the html tag and use AppendText method, only need to use AppendHTML method.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Wed Oct 18, 2017 10:05 am

Hi
That's working. But when i used AppendHTML. It will keep big distance between two lines.

mvadukul21621
 
Posts: 21
Joined: Thu Mar 29, 2012 7:52 pm

Wed Oct 18, 2017 1:13 pm

Don't worry.

I sorted.... You can close this ticket now...

mvadukul21621
 
Posts: 21
Joined: Thu Mar 29, 2012 7:52 pm

Thu Oct 19, 2017 1:25 am

Dear mvadukul21621,

Thanks for your feedback.
Please feel free to contact us if you need any help.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Return to Spire.Doc

cron