Excel ファイルのワークシートの既存の PrinterSettings を削除する

考えられる使用シナリオ

開発者は、Excel が含まれないようにしたい場合があります。。置き場保存された XLSX ファイル内のプリンター設定のファイル。プリンター設定ファイルは次の場所にあります。*「[ファイル「ルート」]\xl\printerSettings」.*このドキュメントでは、Aspose.Cells API を使用して既存のプリンター設定を削除する方法について説明します。

Excel ファイルのワークシートの既存の PrinterSettings を削除する

Aspose.Cells を使用すると、Excel ファイル内の異なるシートに指定されている既存のプリンター設定を削除できます。次のサンプル コードは、ブック内のすべてのワークシートの既存のプリンター設定を削除する方法を示しています。ご覧くださいサンプル Excel ファイル, 出力エクセルファイル、コンソール出力、および参照用のスクリーンショット。

スクリーンショット

todo:画像_代替_文章

サンプルコード

//Source directory
string sourceDir = RunExamples.Get_SourceDirectory();
//Output directory
string outputDir = RunExamples.Get_OutputDirectory();
//Load source Excel file
Workbook wb = new Workbook(sourceDir + "sampleRemoveExistingPrinterSettingsOfWorksheets.xlsx");
//Get the sheet counts of the workbook
int sheetCount = wb.Worksheets.Count;
//Iterate all sheets
for (int i = 0; i < sheetCount; i++)
{
//Access the i-th worksheet
Worksheet ws = wb.Worksheets[i];
//Access worksheet page setup
PageSetup ps = ws.PageSetup;
//Check if printer settings for this worksheet exist
if (ps.PrinterSettings != null)
{
//Print the following message
Console.WriteLine("PrinterSettings of this worksheet exist.");
//Print sheet name and its paper size
Console.WriteLine("Sheet Name: " + ws.Name);
Console.WriteLine("Paper Size: " + ps.PaperSize);
//Remove the printer settings by setting them null
ps.PrinterSettings = null;
Console.WriteLine("Printer settings of this worksheet are now removed by setting it null.");
Console.WriteLine("");
}//if
}//for
//Save the workbook
wb.Save(outputDir + "outputRemoveExistingPrinterSettingsOfWorksheets.xlsx");

コンソール出力

 PrinterSettings of this worksheet exist.

Sheet Name: Sheet1

Paper Size: PaperLegal

Printer settings of this worksheet are now removed by setting it null.

PrinterSettings of this worksheet exist.

Sheet Name: Sheet2

Paper Size: PaperEnvelopeB5

Printer settings of this worksheet are now removed by setting it null.

PrinterSettings of this worksheet exist.

Sheet Name: Sheet3

Paper Size: PaperA6

Printer settings of this worksheet are now removed by setting it null.

PrinterSettings of this worksheet exist.

Sheet Name: Sheet4

Paper Size: PaperA3

Printer settings of this worksheet are now removed by setting it null.