Ciao,
ho avuto lo stesso problema e ho risolto cosi!!!
Protected Sub btnEsportaElencoGiorno_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnEsportaElencoGiorno.Click
SqlDataSource1.SelectCommand = "SELECT ID_Agenda_Sale, Sala, Data_Prenotazione, LEFT(CONVERT(varchar, Data_Prenotazione, 1), 2) AS Mese, DATEPART(yyyy,Data_Prenotazione) AS Anno, CONVERT(VARCHAR(5),Ora_Prenotazione_Inizio,108) AS Ora_Prenotazione_Inizio, CONVERT(VARCHAR(5),Ora_Prenotazione_Fine,108) AS Ora_Prenotazione_Fine, Titolo FROM [AgendaSale] ORDER BY [Data_Prenotazione] ASC, [ID_Agenda_Sale] DESC"
Filtra()
grvLista.DataBind()
Dim table As New iTextSharp.text.pdf.PdfPTable(grvLista.Columns.Count)
table.WidthPercentage = 95
For i As Integer = 0 To grvLista.Rows.Count - 1
Dim widths As Integer() = {30, 75, 40, 40, 200, 250, 0, 0}
'CREA LA RIGA DI INTESTAZIONE
Dim Giorno_OLD As String
If grvLista.Rows(i).Cells(1).Text <> Giorno_OLD Then
Dim cellTextGiorno As String = Server.HtmlDecode(grvLista.Rows(i).Cells(1).Text)
Dim fntBoldTextGiorno As Font = FontFactory.GetFont(FontFactory.HELVETICA, 12, Font.BOLD)
Dim cellGiorno As iTextSharp.text.pdf.PdfPCell = New iTextSharp.text.pdf.PdfPCell(New Phrase(Server.HtmlDecode(" " + UCase(Left(WeekdayName(Weekday(cellTextGiorno, vbMonday), False, vbMonday), 1)) & LCase(Right(WeekdayName(Weekday(cellTextGiorno, vbMonday), False, vbMonday), Len(WeekdayName(Weekday(cellTextGiorno, vbMonday), False, vbMonday)) - 1)) + ""), fntBoldTextGiorno))
cellGiorno.Colspan = 8
cellGiorno.BackgroundColor = New BaseColor(System.Drawing.Color.Silver)
'cellGiorno.Padding = "3"
table.AddCell(cellGiorno)
Giorno_OLD = grvLista.Rows(i).Cells(1).Text
End If
'CREA LE CELLE
For x As Integer = 0 To grvLista.Columns.Count - 1
Dim cellText As String = Server.HtmlDecode(grvLista.Rows(i).Cells(x).Text)
Dim cell As iTextSharp.text.pdf.PdfPCell = New iTextSharp.text.pdf.PdfPCell(New Phrase(cellText))
'cell.Padding = "3"
table.AddCell(cell)
Next
table.SetWidths(widths)
Next
Dim pdfDoc As New Document(PageSize.A4, 10.0F, 10.0F, 10.0F, 10.0F)
PdfWriter.GetInstance(pdfDoc, Response.OutputStream)
pdfDoc.Open()
Dim image As iTextSharp.text.Image = iTextSharp.text.Image.GetInstance(Server.MapPath("../../allegati/TemplatePDF/header.jpg"))
image.ScalePercent(25.0F)
image.Alignment = Element.ALIGN_CENTER
pdfDoc.Add(image)
Dim Spazio As String = "<br>"
For Each element As IElement In HTMLWorker.ParseToList(New StringReader(Spazio), New StyleSheet)
pdfDoc.Add(element)
Next
pdfDoc.Add(table)
Dim Data_Stampa As String = "<span style=""font-size:8px;text-align:right;"">Stampato il " & Now & "</span>"
For Each element1 As IElement In HTMLWorker.ParseToList(New StringReader(Data_Stampa), New StyleSheet)
pdfDoc.Add(element1)
Next
pdfDoc.Close()
Response.ContentType = "application/pdf"
Response.AddHeader("content-disposition", "attachment;filename=ElencoGiornoAgendaSale.pdf")
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.Write(pdfDoc)
Response.End()
End Sub
Studialo un po' e vedi che trovi la soluzione!!!
Queste dovrebbero essere le righe che ti interessano maggiormente!
Dim cellTextGiorno As String = Server.HtmlDecode(grvLista.Rows(i).Cells(1).Text)
Dim cellGiorno As iTextSharp.text.pdf.PdfPCell = New iTextSharp.text.pdf.PdfPCell(New Phrase(Server.HtmlDecode(" " + UCase(Left(WeekdayName(Weekday(cellTextGiorno, vbMonday), False, vbMonday), 1)) & LCase(Right(WeekdayName(Weekday(cellTextGiorno, vbMonday), False, vbMonday), Len(WeekdayName(Weekday(cellTextGiorno, vbMonday), False, vbMonday)) - 1)) + ""), fntBoldTextGiorno))
Ciao
Tommaso