JavaScriptを使用したC++での印刷タイトルの設定方法

可能な使用シナリオ

Excelで印刷タイトルを設定すると、特定の行または列がすべてのページで繰り返され、大きなスプレッドシートを複数ページにわたって印刷する場合に特に便利です。設定する理由は次の通りです:

  1. 読みやすさの向上:印刷タイトルは、見出しをすべてのページで表示し続けることで、データの理解を助けます。各ページで情報を解釈しやすくなります。

  2. 専門的な外観:各ページにヘッダーやラベルを一定して表示することで、印刷されたドキュメントに洗練されたプロフェッショナルな印象を与えます。

  3. ナビゲーションの改善:膨大なデータを含むドキュメントでは、各ページでヘッダーを繰り返すことで、迅速にナビゲートおよび参照でき、ページの行き来を減らすことができます。

  4. エラー低減:すべてのページにヘッダーがあると、誤解やデータ入力エラーの可能性が低減され、ユーザーがデータのコンテキストを簡単に理解できるためです。

  5. 一貫性:重要な情報(列見出しや行ラベルなど)が常に表示されることにより、ドキュメント全体の一貫性と明確さが保たれます。

Excelで印刷タイトルを設定する方法

Excelで印刷タイトルを設定するには、次の手順に従います:

  1. ページレイアウトタブを開く:Excelウィンドウのリボンの「ページレイアウト」タブをクリックします。

  2. 印刷タイトルにアクセス: “ページ設定” グループ内の “印刷タイトル” をクリックします。

  3. 行の繰り返し設定: “ページ設定” ダイアログボックスの “シート” タブに移動します。 “印刷タイトル” セクションで、 “上部で繰り返す行” の横のボックスをクリックし、繰り返す行を選択します。

  4. 列の繰り返し設定(必要に応じて):同様に、 “左側で繰り返す列” の横のボックスをクリックし、繰り返す列を選択します。


  5. 確認して印刷:“OK” をクリックして設定を適用します。ワークシートを印刷すると、指定した行や列がすべてのページに表示されます。

Excelで印刷タイトルをクリアする方法

Excelで印刷タイトルをクリアするには、繰り返す設定された行または列を削除する必要があります。次の手順です:

  1. ページレイアウトタブを開く:Excelウィンドウのリボンの「ページレイアウト」タブをクリックします。

  2. 印刷タイトルにアクセス: “ページ設定” グループ内の “印刷タイトル” をクリックします。

  3. 印刷タイトルをクリア:「ページ設定」ダイアログボックスの「シート」タブに移動します。「先頭行を繰り返す」および「左端列を繰り返す」のテキストボックス内の内容を削除してクリアします。


  4. 確認して閉じる:「OK」をクリックして変更を適用します。

Aspose.Cells for JavaScriptをC++で使用した印刷タイトルの設定方法

指定したシートにプリントタイトルを設定するには、まずサンプルファイルを読み込み、次に望むシートのPageSetupオブジェクトのWorksheet.pageSetupWorksheet.pageSetupのプロパティを変更します。これらのプロパティに範囲文字列を設定するとプリントタイトルが設定されます。

<!DOCTYPE html>
<html>
    <head>
        <title>Aspose.Cells Example - Set Print Titles</title>
    </head>
    <body>
        <h1>Set Print Titles Example</h1>
        <input type="file" id="fileInput" accept=".xls,.xlsx,.csv" />
        <button id="runExample">Run Example</button>
        <a id="downloadLink" style="display: none;">Download Result</a>
        <div id="result"></div>
    </body>

    <script src="aspose.cells.js.min.js"></script>
    <script type="text/javascript">
        const { Workbook, SaveFormat, Utils } = AsposeCells;

        AsposeCells.onReady({
            license: "/lic/aspose.cells.enc",
            fontPath: "/fonts/",
            fontList: [
                "arial.ttf",
                "NotoSansSC-Regular.ttf"
            ]
        }).then(() => {
            console.log("Aspose.Cells initialized");
        });

        document.getElementById('runExample').addEventListener('click', async () => {
            const fileInput = document.getElementById('fileInput');
            if (!fileInput.files.length) {
                document.getElementById('result').innerHTML = '<p style="color: red;">Please select an Excel file.</p>';
                return;
            }

            const file = fileInput.files[0];
            const arrayBuffer = await file.arrayBuffer();

            // Load the workbook from the uploaded file
            const workbook = new Workbook(new Uint8Array(arrayBuffer));

            // Access the desired worksheet
            const worksheet = workbook.worksheets.get(0);

            // Set rows to repeat at the top (e.g., rows 1 and 2)
            worksheet.pageSetup.printTitleRows = "$1:$2";

            // Set columns to repeat at the left (e.g., columns A and B)
            worksheet.pageSetup.printTitleColumns = "$A:$B";

            // Save the workbook as PDF
            const outputData = workbook.save(SaveFormat.Pdf);
            const blob = new Blob([outputData], { type: "application/pdf" });
            const downloadLink = document.getElementById('downloadLink');
            downloadLink.href = URL.createObjectURL(blob);
            downloadLink.download = 'set_print_titles.pdf';
            downloadLink.style.display = 'block';
            downloadLink.textContent = 'Download PDF File';

            document.getElementById('result').innerHTML = '<p style="color: green;">Print titles set successfully! Click the download link to get the PDF.</p>';
        });
    </script>
</html>

出力結果:


Aspose.Cells for JavaScriptをC++で使用した印刷タイトルのクリア方法

指定したシートのプリントタイトルをクリアするには、まずサンプルファイルを読み込み、次に望むシートのPageSetupオブジェクトのWorksheet.pageSetupWorksheet.pageSetupのプロパティを変更します。これらのプロパティを空文字に設定するとプリントタイトルがクリアされます。

<!DOCTYPE html>
<html>
    <head>
        <title>Clear Print Titles Example</title>
    </head>
    <body>
        <h1>Clear Print Titles Example</h1>
        <input type="file" id="fileInput" accept=".xls,.xlsx,.csv" />
        <button id="runExample">Run Example</button>
        <a id="downloadLink" style="display: none;">Download Result</a>
        <div id="result"></div>
    </body>

    <script src="aspose.cells.js.min.js"></script>
    <script type="text/javascript">
        const { Workbook, SaveFormat, Utils } = AsposeCells;

        AsposeCells.onReady({
            license: "/lic/aspose.cells.enc",
            fontPath: "/fonts/",
            fontList: [
                "arial.ttf",
                "NotoSansSC-Regular.ttf"
            ]
        }).then(() => {
            console.log("Aspose.Cells initialized");
        });

        document.getElementById('runExample').addEventListener('click', async () => {
            const fileInput = document.getElementById('fileInput');
            if (!fileInput.files.length) {
                document.getElementById('result').innerHTML = '<p style="color: red;">Please select an Excel file.</p>';
                return;
            }

            const file = fileInput.files[0];
            const arrayBuffer = await file.arrayBuffer();

            // Load the workbook from the selected file
            const workbook = new Workbook(new Uint8Array(arrayBuffer));

            // Access the desired worksheet
            const worksheet = workbook.worksheets.get(0);

            // Clear the rows and columns set to repeat
            worksheet.pageSetup.printTitleRows = "";
            worksheet.pageSetup.printTitleColumns = "";

            // Save the workbook as PDF
            const outputData = workbook.save(SaveFormat.Pdf);
            const blob = new Blob([outputData], { type: 'application/pdf' });
            const downloadLink = document.getElementById('downloadLink');
            downloadLink.href = URL.createObjectURL(blob);
            downloadLink.download = 'clear_print_titles.pdf';
            downloadLink.style.display = 'block';
            downloadLink.textContent = 'Download PDF File';

            document.getElementById('result').innerHTML = '<p style="color: green;">Print titles cleared successfully! Click the download link to get the PDF.</p>';
        });
    </script>
</html>

出力結果: