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 Sep 05, 2017 9:22 am

I am exporting data from asp.net to word. But when i export i can see html tags in word document.

For example

i want this one
Hi This is your item


but i get it wrong like
<p>Hi This is your item</p>

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

Wed Sep 06, 2017 1:46 am

Hi,

Thanks for your inquiry.
To help us find out the root of your issue, could you please share the code you were trying?

Sincerely,
Jane
E-iceblue support team
User avatar

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

Fri Sep 15, 2017 11:03 am

Hi
I want only one header and other rows should be my data.
But my header is also repeating with data...

I just want only one static header row and other data row..

Please see below my code

Dim RowDataCount As Integer = _sql.GetGraphsChartsRowCount()


For Each row In ds.Tables(0).Rows ' My Data row

Dim table As Table = s.AddTable(True)

'Create Header and Data
Dim Header() As String = {"Project Title", "Project Manager", "Project Sponsor", "Status"}



Dim data()() As String = {New String() {row(0), row(1), row(2), row(3)}}


'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
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.Center
'Data Format
Dim TR As TextRange = p.AppendText(Header(i))
TR.CharacterFormat.FontName = "Calibri"
TR.CharacterFormat.FontSize = 14
TR.CharacterFormat.TextColor = Color.Teal
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.Center
TR2.CharacterFormat.FontName = "Calibri"
TR2.CharacterFormat.FontSize = 12
TR2.CharacterFormat.TextColor = Color.Brown
Next c
Next r

Next

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

Mon Sep 18, 2017 6:53 am

Dear mvadukul21621,

Sorry for late reply as weekend.
I made some changes to your code since something was missing. Then I tested the code with the latest Spire.Doc Pack(hot fix) Version:6.0.8. The result is what you want, and it has two rows and the first row is just header and the second row is the data. Please try to use the version. If the issue still happens, please provide us with entire code for further testing.
Code: Select all
        Dim doc As New Document()
        Dim s As Section = doc.AddSection()
        Dim dt As New DataTable()
        dt.Columns.Add("colum1", GetType(String))
        dt.Columns.Add("colum2", GetType(String))
        dt.Columns.Add("colum3", GetType(String))
        dt.Columns.Add("colum4", GetType(String))
        Dim row As DataRow
        row = dt.NewRow()
        row(0) = "1"
        row(1) = "1"
        row(2) = "1"
        row(3) = "1"
        dt.Rows.Add(row)
        Dim table As Table = s.AddTable(True)

        'Create Header and Data
        Dim Header As String() = {"Project Title", "Project Manager", "Project Sponsor", "Status"}

        Dim data As String()() = {New String() {row(0), row(1), row(2), row(3)}}

        '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
        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.Center
            'Data Format
            Dim TR As TextRange = p.AppendText(Header(i))
            TR.CharacterFormat.FontName = "Calibri"
            TR.CharacterFormat.FontSize = 14
            TR.CharacterFormat.TextColor = Color.Teal
            TR.CharacterFormat.Bold = True
        Next

        '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.Center
                TR2.CharacterFormat.FontName = "Calibri"
                TR2.CharacterFormat.FontSize = 12
                TR2.CharacterFormat.TextColor = Color.Brown
            Next
        Next
        doc.SaveToFile("insertTable11537.docx", FileFormat.Docx)


Sincerely,
Betsy
E-iceblue support team
User avatar

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

Tue Sep 19, 2017 9:15 am

Hi Jane,

I can do this things 1 header and 1 row.

But i have 1 header and 5 data row in my data table.
I want one header and another 5 data row.



Regards
Manish

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

Tue Sep 19, 2017 9:30 am

Dear Manish,

Thanks for your feedback.
Because the data only has one row, so the result has 1 header and 1 row.
Code: Select all
        Dim data As String()() = {New String() {row(0), row(1), row(2), row(3)}}

Please change it to the data which has 5 rows, then you will get one header and another 5 data rows, for example.
Code: Select all
        Dim data As String()() = {New String() {"1", "1", "1", "1"}, New String() {"2", "2", "2", "2"}, New String() {"3", "3", "3", "3"}, New String() {"4", "4", "4", "4"}, New String() {"5", "5", "5", "5"}}

If there is still issue, please provide entire code for testing.

Sincerely,
Betsy
E-iceblue support team
Last edited by Betsy.jiang on Tue Sep 19, 2017 9:42 am, edited 1 time in total.
User avatar

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

Tue Sep 19, 2017 9:34 am

Hi Jane,

Yes you are right.

But i have 5 records in my data table. But it will print only last one.

Please see below example. It is working but it is printing only last one.

Private Sub Test()
Dim doc As New Document()
Dim s As Section = doc.AddSection()

Dim dt As New DataTable()
dt = _sql.GetTest1()




'Dim dt As New DataTable()
dt.Columns.Add("colum1", GetType(String))
dt.Columns.Add("colum2", GetType(String))
dt.Columns.Add("colum3", GetType(String))
dt.Columns.Add("colum4", GetType(String))

Dim row As DataRow
row = dt.NewRow()
For Each row In dt.Rows
row(0) = row.Item(0).ToString
row(1) = row.Item(1).ToString
row(2) = row.Item(2).ToString
row(3) = row.Item(3).ToString
Next


Dim table As Table = s.AddTable(True)

'Create Header and Data
Dim Header As String() = {"Project Title", "Project Manager", "Project Sponsor", "Status"}

Dim data As String()() = {New String() {row(0), row(1), row(2), row(3)}}

'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
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.Center
'Data Format
Dim TR As TextRange = p.AppendText(Header(i))
TR.CharacterFormat.FontName = "Calibri"
TR.CharacterFormat.FontSize = 14
TR.CharacterFormat.TextColor = Color.Teal
TR.CharacterFormat.Bold = True
Next

'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.Center
TR2.CharacterFormat.FontName = "Calibri"
TR2.CharacterFormat.FontSize = 12
TR2.CharacterFormat.TextColor = Color.Brown
Next
Next
'doc.SaveToFile("insertTable11537.docx", FileFormat.Docx)
doc.SaveToFile("insertTable11537.doc", FileFormat.Doc, Response, HttpContentType.Attachment)

End Sub


You sent me below code to change from 1 data to 5 rows. But you can't change it.
Because you don't know how many data into the data table ?
---------------------------------------------------
CODE: SELECT ALL
Dim data As String()() = {New String() {row(0), row(1), row(2), row(3)}}

Please change it to the data which has 5 rows, then you will get one header and another 5 data rows, for example.
CODE: SELECT ALL
Dim data As String()() = {New String() {"1", "1", "1", "1"}, New String() {"2", "2", "2", "2"}, New String() {"3", "3", "3", "3"}, New String() {"4", "4", "4", "4"}, New String() {"5", "5", "5", "5"}}

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

Tue Sep 19, 2017 10:05 am

Dear mvadukul2162,

Thanks for your prompt response.
Please note the data you were using is just one dimensional array. You need to convert the data to multidimensional array, then fill the data. Sample code for your kind reference.
Code: Select all
Dim rowCount As Integer = dt.Rows.Count
Dim colCount As Integer = dt.Columns.Count
Dim data As String()() = New String(rowCount - 1)() {}
For i As Integer = 0 To rowCount - 1
   data(i) = New String(colCount - 1) {}
   For j As Integer = 0 To colCount - 1
      data(i)(j) = dt.Rows(i)(j).ToString()
   Next
Next


Sincerely,
Betsy
E-iceblue support team
User avatar

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

Tue Sep 19, 2017 10:13 am

Hi I have done below code.

but i can see only last record from all the records.

Please can you see where do i mistake? I m too confused now.



Private Sub Test()
Dim doc As New Document()
Dim s As Section = doc.AddSection()

Dim dt As New DataTable()
dt = _sql.GetTest1()




'Dim dt As New DataTable()
dt.Columns.Add("colum1", GetType(String))
dt.Columns.Add("colum2", GetType(String))
dt.Columns.Add("colum3", GetType(String))
dt.Columns.Add("colum4", GetType(String))

Dim row As DataRow
row = dt.NewRow()
For Each row In dt.Rows
row(0) = row.Item(0).ToString
row(1) = row.Item(1).ToString
row(2) = row.Item(2).ToString
row(3) = row.Item(3).ToString
Next

Dim rowCount As Integer = dt.Rows.Count
Dim colCount As Integer = dt.Columns.Count

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

Dim table As Table = s.AddTable(True)

'Create Header and Data
Dim Header As String() = {"Project Title", "Project Manager", "Project Sponsor", "Status"}

data = {New String() {row(0), row(1), row(2), row(3)}}

'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
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.Center
'Data Format
Dim TR As TextRange = p.AppendText(Header(i))
TR.CharacterFormat.FontName = "Calibri"
TR.CharacterFormat.FontSize = 14
TR.CharacterFormat.TextColor = Color.Teal
TR.CharacterFormat.Bold = True
Next

'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.Center
TR2.CharacterFormat.FontName = "Calibri"
TR2.CharacterFormat.FontSize = 12
TR2.CharacterFormat.TextColor = Color.Brown
Next
Next
'doc.SaveToFile("insertTable11537.docx", FileFormat.Docx)
doc.SaveToFile("insertTable11537.doc", FileFormat.Doc, Response, HttpContentType.Attachment)

End Sub

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

Tue Sep 19, 2017 10:38 am

Hi Jane,

Its working. Sorted.. Thanks for your sample code.

Regards

Manish

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

Tue Sep 19, 2017 11:25 am

hi

One more issue.

When i export my data shows like <p> text </p>

i dont want html character.

So i have function

Function StripHTMLTags(ByVal HTMLToStrip As String, Optional ByVal ReplaceChar As String = "") As String
If (HTMLToStrip <> String.Empty) Then
Return Regex.Replace(HTMLToStrip, "<.*?>", ReplaceChar)
End If
Return String.Empty
End Function

Where can i call my StripHTMLTags() in your code

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) = dt.Rows(i1)(j).ToString()
Next
Next

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

Tue Sep 19, 2017 11:27 am

No worries.

Its also done.

thanks.

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

Wed Sep 20, 2017 1:26 am

Dear mvadukul21621,

Glad to hear that your issues have been resolved.
Please feel free to contact us if you have any question.

Sincerely,
Betsy
E-iceblue support team
User avatar

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

Return to Spire.Doc