VB.NET 에서 엑셀 인쇄 설정
C1FLEXGRID를 화면 그대로 엑셀 전환 후 엑셀 편집과 인쇄 설정
Dim SAVEFILENAME As String = String.Empty
Dim DIR As String = String.Empty
SaveFileDialog1.Filter = "EXCEL FILES (*.XLS)|*.XLS"
SaveFileDialog1.FilterIndex = 1
SaveFileDialog1.RestoreDirectory = True
SaveFileDialog1.FileName = SAVEFILENAME
If SaveFileDialog1.ShowDialog() = DialogResult.OK Then
'-- 이력등록
C1FLEXGRID.Focus()
C1FLEXGRID.Select(0, 0, C1ScheduleChart.Rows.Count - 1, C1ScheduleChart.Cols.Count - 1)
C1FLEXGRID.SaveExcel(SaveFileDialog1.FileName, "", (C1.Win.C1FlexGrid.FileFlags.IncludeFixedCells AndAlso C1.Win.C1FlexGrid.FileFlags.AsDisplayed))
DIR = SaveFileDialog1.FileName
excelApp = CreateObject("Excel.Application")
excelBook = excelApp.Workbooks.Open(DIR, , True)
excelWorksheet = excelBook.Worksheets(1)
excelProcess = System.Diagnostics.Process.GetProcessesByName("EXCEL")
For i As Integer = 0 To excelProcess.Length - 1
arlProcessID.Add(excelProcess(i).Id)
Next
excelApp.DisplayAlerts = False
excelApp.Visible = False
With excelWorksheet
편집시작. 제목 셀병합 후 중앙정렬. 폰트 굵게
.Range("A1", "A2").EntireRow.Insert()
.Range("B1", "B2").EntireRow.Font.Size = 12
.Range("B1").EntireRow.Font.Bold = True
.Range("B1").Value = "Production Schedule(" + CMB_YEAR.Text + "." + CMB_MONTH.Text + ")"
.Range("B1", "AG1").Merge()
.Range("A1", "A3").RowHeight = 24
.Range("B1").Style.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter
.Range("B2").Value = CMB_FACTORY.SelectedValue
.Range("B1", "AG1").ColumnWidth = 10
.Range("A4", "AG60").RowHeight = 46
출력범위 셀서식 테두리 선 스타일 설정
.Range("B3", .Cells(C1FLEXGRID.Rows.Count + 2, C1FLEXGRID.Cols.Count)).Borders.LineStyle = Excel.XlLineStyle.xlDot
.Range("B3", .Cells(C1FLEXGRID.Rows.Count + 2, C1FLEXGRID.Cols.Count)).BorderAround2(Excel.XlLineStyle.xlDot, Excel.XlBorderWeight.xlHairline)
For ii As Integer = 1 To C1ScheduleChart.Rows.Count - 1
For i As Integer = 0 To C1ScheduleChart.Cols.Count - 1
C1FELXGRID의 이미지를 엑셀에 붙여 넣는 방법
Try
If Not IsNothing(C1ScheduleChart.GetCellImage(ii, i)) Then
Clipboard.SetDataObject(C1ScheduleChart.GetCellImage(ii, i), False)
.Cells(ii + 3, i + 1).Select()
.Paste()
With excelApp.Selection.ShapeRange
.LockAspectRatio = False
.Width = 35 : .Height = 40
.Top = .Top + 5
.Left = .Left + 5
End With
End If
Catch ex As Exception
End Try
Next
Next
인쇄설정-여백조정
.PageSetup.LeftMargin = excelApp.Application.InchesToPoints(0.3)
.PageSetup.RightMargin = excelApp.Application.InchesToPoints(0.3)
.PageSetup.TopMargin = excelApp.Application.InchesToPoints(0.5)
.PageSetup.BottomMargin = excelApp.Application.InchesToPoints(0.5)
.PageSetup.HeaderMargin = excelApp.Application.InchesToPoints(0.3)
.PageSetup.FooterMargin = excelApp.Application.InchesToPoints(0.3)
인쇄설정-인쇄제목반복행설정
.PageSetup.PrintTitleRows = "$1:$2"
인쇄설정-한페이지에 모든 열 맞추기
Zoom, FitToPagesTall = False, FitToPagesWide = 1 3개가 세트입니다.
.PageSetup.Zoom = False
.PageSetup.FitToPagesTall = False
.PageSetup.FitToPagesWide = 1
End With
excelApp.Visible = True
excelWorksheet.PrintPreview()
#vb엑셀셀서식테두리선스타일, #VB엑셀한페이지에모든열맞추기, #VB엑셀한페이지에모든행맞추기, #VB인쇄제목반복행설정, #VB인쇄설정여백조정
'VB.NET&MSSQL' 카테고리의 다른 글
VB.NET 콤보박스 CHECKBOX 로 다중선택구현하기 (0) | 2020.07.17 |
---|---|
VB.NET 관리자 권한으로 실행하기 (0) | 2020.06.26 |
[MSSQL] 날짜 타입 변경 (0) | 2020.04.27 |
[MS-SQL] SQL 날짜 함수 (0) | 2020.04.27 |
[MSSQL] SQL SERVER BACKUP SCHEDULE 설정 (0) | 2020.04.26 |
댓글