Js Tablo yazdırma Scripti

Html Sayfalarda bir tablo id ile tetiklendiğinde tablo içeriğini yazdırmaya aktaran script

<script>
function PrintTable(tabloId) {
    let table = document.querySelector(tabloId);
    if (!table) {
        console.error("Tablo bulunamadı: " + tabloId);
        return;
    }

    let printWindow = window.open('', '', 'width=800,height=600');
    printWindow.document.write('<html><head><title>Tablo Yazdır</title>');
    printWindow.document.write('<style>');
    printWindow.document.write('table { border-collapse: collapse; width: 100%; }');
    printWindow.document.write('th, td { border: 1px solid black; padding: 8px; text-align: left; }');
    printWindow.document.write('</style></head><body>');
    
    printWindow.document.write(table.outerHTML); // Sadece tablonun içeriğini ekler
    printWindow.document.write('</body></html>');
    
    printWindow.document.close();
    printWindow.print();
}
</script>

Örnek Kullanımı

	<button onclick="PrintTable('#Tablo1')">Yazdır</button>
Js Tablodan Pdf Aktarım Scripti

Html Sayfalarda bir tablo id ile tetiklendiğinde tablo içeriğini pdf aktaran script

<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf-autotable/3.5.27/jspdf.plugin.autotable.min.js"></script>

<script>


function TabloPDF(tabloId, dosyaAdi = "tablo.pdf") {
    let table = document.querySelector(tabloId);
    if (!table) {
        console.error("Tablo bulunamadı: " + tabloId);
        return;
    }

    let { jsPDF } = window.jspdf;
    let doc = new jsPDF();
	  doc.addFont('font/roboto.ttf', 'Roboto', 'normal');
  doc.setFont("Roboto", "normal");
 
 ;
    doc.autoTable({
        html: table ,
        styles: {
            font: "Roboto", // Alternatif: "times"
            fontStyle: "normal"
        }
    });

    doc.save(dosyaAdi);
}
</script>

Örnek Kullanımı

&lt;button onclick="TabloPDF('#Tablo1')">PDF İndir&lt;/button>
Js Tablodan Excel Aktarım Scripti

Html Sayfalarda bir tablo id ile tetiklendiğinde tablo içeriğini excele aktaran script

<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.18.5/xlsx.full.min.js"></script>
<script>
function TabloExcel(tabloId, dosyaAdi = "tablo.xlsx") {
    let table = document.querySelector(tabloId);
    if (!table) {
        console.error("Tablo bulunamadı: " + tabloId);
        return;
    }

    let wb = XLSX.utils.book_new();
    let ws = XLSX.utils.table_to_sheet(table);
    XLSX.utils.book_append_sheet(wb, ws, "Sayfa1");

    XLSX.writeFile(wb, dosyaAdi);
}
</script>

örnek Kullanımı

  <button onclick="TabloExcel('#Tablo1')">Excel İndir</button>
Sql Server Tablo Boyutlarını Gösteren Sorgu

Aşağıdaki Sql Scriptini Kullanarak Hangi Tabloda Kaç Satır var MB olarak Ne Kadar Yer Kaplıyor öğrenebilirsiniz

SELECT 
    t.NAME AS TableName,
    s.Name AS SchemaName,
    p.rows AS RowCounts,
    (SUM(a.total_pages) * 8) / 1024 AS TotalSizeMB,
    (SUM(a.used_pages) * 8) / 1024 AS UsedSizeMB,
    (SUM(a.data_pages) * 8) / 1024 AS DataSizeMB
FROM 
    sys.tables t
INNER JOIN 
    sys.indexes i ON t.OBJECT_ID = i.object_id
INNER JOIN 
    sys.partitions p ON i.object_id = p.OBJECT_ID AND i.index_id = p.index_id
INNER JOIN 
    sys.allocation_units a ON p.partition_id = a.container_id
INNER JOIN 
    sys.schemas s ON t.schema_id = s.schema_id
WHERE 
    t.is_ms_shipped = 0
GROUP BY 
    t.Name, s.Name, p.Rows
ORDER BY 
    TotalSizeMB DESC;