HTML<table cellspacing=0 style="border-collapse: collapse"><tr><td style='border: 1px solid black'>1</td> <td style='border: 1px solid black'>2</td> <td style='border: 1px solid black'>3</td></tr><tr><td style='border: 1px solid black'>One</td> <td style='border: 1px solid black'>Two</td> <td style='border: 1px solid black'>Three</td></tr><tr><td style='border-width: 1 0 0; border-style: solid; border-color: black'></td> <td style='border-width: 1 0 0; border-style: solid; border-color: black'></td> <td style='border: 1px solid black'>Finish</td></tr></table>
C++ (Qt) QString html = "<html><body>"; html += "<table cellspacing=0 cellpadding = 2 style='border-width: 1px; border-style: solid; border-color: #000000'>"; html += "<tr>"; html += "<td>1</td>"; html += "<td>2</td>"; html += "<td>3</td>"; html += "</tr>"; html += "<tr>"; html += "<td>One</td>"; html += "<td>Two</td>"; html += "<td>Three</td>"; html += "</tr>"; html += "<tr>"; html += "<td></td>"; html += "<td></td>"; html += "<td>Finish</td>"; html += "</tr>"; html += "</table></body></html>"; page->setHtml(html);
C++ (Qt) QString html = "<html><body>"; html += "<table cellspacing=0 cellpadding=2'>"; html += "<tr>"; html += "<td style='border-width: 1px; border-style: solid; border-color: #000000'>1</td>"; html += "<td style='border-width: 1px; border-style: solid; border-color: #000000'>2</td>"; html += "<td style='border-width: 1px; border-style: solid; border-color: #000000'>3</td>"; html += "</tr>"; html += "<tr>"; html += "<td style='border-width: 1px; border-style: solid; border-color: #000000'>One</td>"; html += "<td style='border-width: 1px; border-style: solid; border-color: #000000'>Two</td>"; html += "<td style='border-width: 1px; border-style: solid; border-color: #000000'>Three</td>"; html += "</tr>"; html += "<tr>"; html += "<td style='border-style: none;'></td>"; html += "<td style='border-style: none;'></td>"; html += "<td style='border-width: 1px; border-style: solid; border-color: #000000'>Finish</td>"; html += "</tr>"; html += "</table></body></html>"; page->setHtml(html);
C++ (Qt)void MainWindow::preview(){ QPrinter printer; printer.setPageSize(QPrinter::A4); printer.setOrientation(QPrinter::Portrait); printer.setPageMargins(10,10,10,10,QPrinter::Millimeter); QPrintPreviewDialog print_preview(&printer, this); print_preview.setWindowState(Qt::WindowMaximized); connect(&print_preview, SIGNAL(paintRequested(QPrinter*)), this, SLOT(paint_pages(QPrinter*))); print_preview.exec();} void MainWindow::paint_pages(QPrinter *printer){ QList<QWebView*> pages; QWebView *current = 0; QPainter painter(printer); int i = 0; while(i <= 100){ current = new QWebView(); pages << current; i = populate_web(current, printer, i); } int pc = pages.count(); for(i = 0; i < pc; i++){ if(i != 0) printer->newPage(); pages.at(i)->render(&painter); } for(i = 0; i < pc; i++) delete pages.at(i);} int MainWindow::populate_web(QWebView *pg, QPrinter *printer, int n){ QString html = "<html><body>"; html += "<table cellspacing=0 border = 1 style='border-collapse: collapse'>"; int page_height = printer->paperRect(QPrinter::Point).height(); for(++n; n <= 100; n++){ html += QString("<tr><td width=200>%1</td><td width=200>%2</td><td width=300>%3</td></tr>").arg(n).arg(n*n).arg(n*n*n); QString html2 = html + "</table></body></html>"; pg->setHtml(html2); int content_height = pg->page()->mainFrame()->contentsSize().height(); if(content_height + 20 > page_height) break; } html += "</table></body></html>"; pg->setHtml(html); return n;}
doc->setCellText(1,3,"3"); doc->setCellText(2,3,"Three");doc->setCellText(2,3,"Finish");
doc->setCellText(1,3,"3"); doc->setCellText(2,3,"Three");doc->setCellText(3,3,"Finish");