Imports System.Configuration
Imports System.IO
Imports FarPoint.Win.Spread
Imports FarPoint.Win.Spread.Model
Imports WindowsApplication1.Intage.JTT.EP.CloseContactReport.Service.Report

Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        For i As Integer = 0 To 500
            Dim Form = New ReportForm
            Form.Show()
            Form.Hide()

            Me.fpSpread = Form.fpSpread
            Dim xmlPatch = Application.StartupPath + "\aaaa.xml"
            Me.fpSpread.Open(xmlPatch)

            ' テンプレートシートを削除
            Me.fpSpread.Sheets.Remove(Me.fpSpread_Sheet1)
            Me.fpSpread.ActiveSheet = Me.fpSpread.Sheets(0)

            Form.Close()

            Dim printset As PrintInfo = New PrintInfo()
            printset.PrintToPdf = True
            printset.PdfFileName = Application.StartupPath + "\" + i.ToString + ".pdf"

            printset.BestFitWithSpan = True
            printset.PdfWriteMode = FarPoint.Win.Spread.PdfWriteMode.New
            printset.Orientation = FarPoint.Win.Spread.PrintOrientation.Landscape
            printset.UseMax = True
            printset.Centering = Centering.Horizontal
            printset.PaperSize = New System.Drawing.Printing.PaperSize("A4", 1169, 826)
            printset.ShowBorder = False
            printset.ZoomFactor = 0.9

            'printset.Margin.Left = Me.Margin_Left
            'printset.Margin.Top = Me.Margin_Top
            'printset.Margin.Bottom = Me.Margin_Bottom
            'printset.Margin.Right = Me.Margin_Left

            Me.fpSpread.ActiveSheet.PrintInfo = printset
            Me.fpSpread.SafePrint(Me.fpSpread, -1)
        Next
    End Sub
End Class
