2017-11-29 3 views
0

현재 각 선택한 항목을 읽고 그 안에 항목의 바코드가있는 셀을 만들 때 (내보내기 할 셀은 사용자가 입력 한 수량에 따라 다름) DataGridView에서 루프를 수행하고 있지만 내보내려고하면 1 바코드 레이블 (1 pdfCell) 내 테이블에 열 개수가 5 있다는 것을 의미하는 pdfTable.Columns (5)가 있기 때문에 'pdfTable이 비어 있습니다. 내보낼 수없는 5로 나눌 수없는 셀 수량을 내 보냅니다.pdfCell 개수와 같지 않거나 나눌 수없는 pdfTable을 내보내는 방법은 무엇입니까?

예 1 : 아이템 - 바나나 (10 바코드 인쇄) - 수출

예 2 : 아이템 - 애플 (1 바코드 인쇄) - 1 (하나)이 적용되지 않기 때문에 수출되지 않음 (PDFTable 빈입니다) 5 (5) 인 열 수와 함께 pdfTable의 단일 행. 여기

는 내 코드 '인쇄 바코드 버튼 레이블'입니다 :

여기
Public Function print_itembarcodes(lbl169 As Label) 
    Dim pdfTable As New PdfPTable(5) 
    pdfTable.DefaultCell.Padding = 3 
    pdfTable.WidthPercentage = 100 
    pdfTable.HorizontalAlignment = Element.ALIGN_CENTER 
    pdfTable.DefaultCell.Border = Rectangle.NO_BORDER 

    For i As Integer = 0 To Admin_Menu.BarcodePrintListGrid.Rows.Count - 1 
     Admin_Menu.Label169.Text = Admin_Menu.BarcodePrintListGrid.Rows(i).Cells(1).Value 'Item Barcode' 
     Barcode.process_printbarcode(Admin_Menu.Label169) 'Make barcode image function' 
     save_printbarcode() 'Save barcode to desktop function' 

     For j As Integer = 0 To Admin_Menu.BarcodePrintListGrid.Rows(i).Cells(5).Value 'Quantity of barcodes to be printed per item' 
      pdfTable.AddCell(create_barcodecell) 'Add cell with barcode function' 
     Next 

    Next 


    Try 

     'Exporting to PDF 
     Dim folderPath As String = "C:\Temp\" 
     If Not Directory.Exists(folderPath) Then 
      Directory.CreateDirectory(folderPath) 
     End If 
     Using stream As New FileStream(folderPath & "temp2.pdf", FileMode.Create) 
      Dim pdfdoc As New Document(PageSize.A4, 15.0F, 15.0F, 10.0F, 20.0F) 
      PdfWriter.GetInstance(pdfdoc, stream) 
      pdfdoc.Open() 
      pdfdoc.Add(pdfTable) 'Table Declaration' 
      pdfdoc.Close() 
      stream.Close() 


      System.Diagnostics.Process.Start("C:\\Temp\\temp2.pdf") 

     End Using 


    Catch ex As MySqlException 
     MsgBox(ex.Message) 
    Finally 
     MysqlConn.Dispose() 
    End Try 

    Return True 
End Function 

는 바코드 셀을 만들기위한 내 코드입니다 :

Public Function create_barcodecell() 
    Dim SaveFileDialog1 = "D:\School\Capstone\Sta. Lucia East Bowling and Billiard Hall Management System\Item Barcodes\" 
    Dim Barcode2 As Image = Image.GetInstance(SaveFileDialog1 + Admin_Menu.Label169.Text + ".jpg") 'Barcode Image' 
    Barcode2.ScaleAbsolute(80.0F, 25.0F) 
    img.ScalePercent(15.0F) 'Company Logo Image' 
    img.Alignment = iTextSharp.text.Image.ALIGN_RIGHT 


    Dim titleFont = FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8) 
    Dim paragraph As New Paragraph() 

    paragraph.Add(New Chunk(img, 0, 0)) 
    paragraph.Add(New Chunk("  Item Tag", titleFont)) 

    Dim pdfCell As New PdfPCell 
    pdfCell.UseVariableBorders = True 
    pdfCell.BackgroundColor = BaseColor.GRAY 
    pdfCell.BorderColorLeft = BaseColor.GREEN 
    pdfCell.BorderColorRight = BaseColor.GREEN 
    pdfCell.BorderColorTop = BaseColor.GREEN 
    pdfCell.BorderColorBottom = BaseColor.GREEN 


    pdfCell.AddElement(paragraph) 
    pdfCell.AddElement(Barcode2) 
    pdfCell.AddElement(New Paragraph("  " + Admin_Menu.Label169.Text, titleFont)) 


    Return pdfCell 
End Function 
+0

a) 'Option Strict'를 켜십시오. b) 명확한 문제 문이 없기 때문에 귀하의 게시물에 3 개의 가까운 표가 표시됩니다 (아마). * PdfTable/Document가 비어 있습니다. * oh-by-the-way 절의 일종으로 tacked됩니다. c) 우리는 귀하가 게시하고 알려주는 귀하의 응용 프로그램에 대해 더 이상 알지 못합니다. 따라서 BarcodePrintListGrid.Rows (i) .cells (5) .value의 언급은 col 5가 나타내는 것을 모르기 때문에 아무 것도 알려주지 않습니다. d) Admin_menu 란 무엇입니까? – Plutonix

+0

@Plutonix Column 5는 사용자가 해당 항목에 대해 인쇄 할 바코드 레이블의 수량 값입니다.예를 들어, Item-Banana (인쇄 할 5 개의 바코드) 5는 인쇄 할 바코드 인 5 열의 값입니다. Admin_Menu는 내 게시물에 언급 된 모든 컨트롤이있는 양식입니다. –

+0

@Plutonix 오류가 'for j as integer = 0 to Admin_Menu.BarcodePrintListGrid.Rows (i) .Cells (5) .Value'루프에 있습니다.이 값을 '3'으로 변경하면 4 개의 바코드 레이블이 인쇄되었으므로 변경했습니다. 다른 숫자가 다시 빈 테이블로 돌아왔다. ... –

답변

0

주요 문제는

5로 나눌 수없는 셀 수량을 내보내려고하면 내보낼 수 없습니다. 해당 테이블 행의 나머지 셀이 비어있는 것으로 경우

, 당신은 당신이 5

어떻게 할 수로 나누어 세포의 숫자를 할 때까지 간단하게 추가 빈 셀을 추가하여이 문제를 해결할 수 빈 셀을 추가합니까?

pdfTable에 새로운 빈 셀을 추가하는 구문이 일부 수정을해야 할 수도 있습니다, 그래서 나는,이 세기의 시작부터 어떤 VB 프로그래밍을하지 않은,하지만 기본적으로 당신은 단순히

pdfTable.AddCell(New PdfPCell()) 

을한다.

어떻게 5로 나눌 수있을 때까지 빈 셀을 추가 할 수 있습니까?

이미 추가 한 셀 수를 계산하고 나머지없이 5로 나눌 수있을 때까지 추가하십시오.

Dim Count as Integer = 0 
For j As Integer = 1 To Admin_Menu.BarcodePrintListGrid.Rows(i).Cells(5).Value 'Quantity of barcodes to be printed per item' 
    pdfTable.AddCell(create_barcodecell) 'Add cell with barcode function' 
    Count = Count + 1 
Next 
While count Mod 5 <> 0 
    pdfTable.AddCell(New PdfPCell()) 
    Count = Count + 1 
End While 

는 (... 나는 j 여전히 이전 For 루프 외부에 존재 여부를 특히 더 이상 VB 세부 사항에 대해 확실하지 않다 어느는. 그에 따라 별도의 카운터를 필요하지 않을 수있다 가치)
+0

지금 마지막 문제가 하나 있습니다 .. 5로 나눌 수없는 숫자를 인쇄 할 때마다 셀 번호가 1 씩 올라갑니다. 6처럼 7이됩니다. 1이됩니다. 2. 그리고 내가 셀 값을 1로 빼낼려고 할 때. 작동하지 않는다. –

+0

빈 셀에 대해 말하는 것이 아니다. 내가 만든 바코드가있는 셀에 대해 얘기하고 있습니다. –

+0

@LuciferRodstark 아, 아마도 1에서 루프를 시작해야합니다. 대답을 편집 할 것입니다. – mkl

관련 문제