Ciao Ragazzi,
ho scritto questo programma per compilare un modulo form in pdf e salvare i file prendendo i dati da un file Excel.
Il programma funziona, ma volevo utilizzare l'opzione FormFlattening = True, ma ricevo un eccezione "Field flattening is not supported in append mode"
non riesco a capire dove sbaglio?
Grazie Stefano
Module mainModule
    Sub Main()
        Dim excel As New X.Application()
        Dim int_Lotto As Integer = 0
        Dim str_Titolo1 As String = ""
        Dim str_Titolo2 As String = ""
        Dim strNomeFile As String = ""
        Dim str_Titolo3 As String = ""
        Dim workbook As X.Workbook = excel.Workbooks.Open("C:\_Lavori\_Pini\14_Cartigli_Chiara\elenco_cartigli.xlsx")
        Dim worksheet As X.Worksheet = TryCast(workbook.ActiveSheet, X.Worksheet)
        Dim init_row As Excel.Range = DirectCast(worksheet.Cells(1, 1), Excel.Range)
        Dim fin_row As Excel.Range = DirectCast(worksheet.Cells(1, 2), Excel.Range)
        For r = init_row.Value To fin_row.Value
            Dim pdfTemp As String = ""
            Dim newFile As String = ""
            Dim lotto As Excel.Range = DirectCast(worksheet.Cells(r, 1), Excel.Range)
            int_Lotto = lotto.Value
            Dim titolo1 As Excel.Range = DirectCast(worksheet.Cells(r, 2), Excel.Range)
            str_Titolo1 = titolo1.Value
            Dim titolo2 As Excel.Range = DirectCast(worksheet.Cells(r, 3), Excel.Range)
            str_Titolo2 = titolo2.Value
            Dim titolo3 As Excel.Range = DirectCast(worksheet.Cells(r, 4), Excel.Range)
            str_Titolo3 = titolo3.Value
            Dim nomefile As Excel.Range = DirectCast(worksheet.Cells(r, 5), Excel.Range)
            strNomeFile = nomefile.Value
            Select Case int_Lotto
                Case 1
                    pdfTemp = "C:\_Lavori\_Pini\14_Cartigli_Chiara\PDF\1.pdf"
                    newFile = "C:\_Lavori\_Pini\14_Cartigli_Chiara\PDF\" & int_Lotto & "\" & strNomeFile & ".PDF"
                Case 2
                    pdfTemp = "C:\_Lavori\_Pini\14_Cartigli_Chiara\PDF\2.pdf"
                    newFile = "C:\_Lavori\_Pini\14_Cartigli_Chiara\PDF\" & int_Lotto & "\" & strNomeFile & ".PDF"
                Case 3
                    pdfTemp = "C:\_Lavori\_Pini\14_Cartigli_Chiara\PDF\3.pdf"
                    newFile = "C:\_Lavori\_Pini\14_Cartigli_Chiara\PDF\" & int_Lotto & "\" & strNomeFile & ".PDF"
                Case 4
                    pdfTemp = "C:\_Lavori\_Pini\14_Cartigli_Chiara\PDF\4.pdf"
                    newFile = "C:\_Lavori\_Pini\14_Cartigli_Chiara\PDF\" & int_Lotto & "\" & strNomeFile & ".PDF"
                Case 8
                    pdfTemp = "C:\_Lavori\_Pini\14_Cartigli_Chiara\PDF\8.pdf"
                    newFile = "C:\_Lavori\_Pini\14_Cartigli_Chiara\PDF\" & int_Lotto & "\" & strNomeFile & ".PDF"
            End Select
            Dim pdfReader As New PdfReader(pdfTemp)
            Dim pdfStamper As New PdfStamper(pdfReader, New FileStream(newFile, FileMode.Create), "\6c", True)
            Dim memStream = New MemoryStream()
            Dim pdfFormFields As AcroFields = pdfStamper.AcroFields
            pdfStamper.FormFlattening = True
            pdfFormFields.SetField("TITOLO1", str_Titolo1)
            pdfFormFields.SetField("TITOLO2", str_Titolo2)
            pdfFormFields.SetField("TITOLO3", str_Titolo3)
            pdfStamper.Close()
        Next
        workbook.Close()
        excel.Quit()
    End Sub