Sayfa Yapısı ve Yazdırma Seçenekleri
Bazen, geliştiricilerin yazdırma sürecini kontrol etmek için sayfa düzenini ve yazdırma ayarlarını yapılandırması gerekir. Sayfa yapısı ve yazdırma ayarları, çeşitli seçenekler sunar ve Aspose.Cells’de tamamen desteklenir.
Bu makale, Visual Studio.Net’te bir konsol uygulamasının nasıl oluşturulacağını ve Aspose.Cells API kullanarak birkaç basit kod satırıyla sayfa düzeni ve yazdırma seçeneklerini bir çalışma sayfasına nasıl uygulayacağınızı gösterir.
Sayfa ve Yazdırma Ayarları ile Çalışma
Bu örnek için, Microsoft Excel’de bir çalışma kitabı oluşturduk ve sayfa düzenini ve yazdırma seçeneklerini ayarlamak için Aspose.Cells’i kullandık.
Sayfa Yapısı Seçeneklerini ayarlamak için Aspose.Cells’i kullanma
Önce Microsoft Excel’de basit bir çalışma sayfası oluşturun. Ardından ona sayfa yapısı seçeneklerini uygulayın. Kodu çalıştırmak, aşağıdaki ekran görüntüsündeki gibi Sayfa Yapısı seçeneklerini değiştirir.
Çıktı dosyası. |
---|
![]() |
- Microsoft Excel’de bazı verilerle bir çalışma sayfası oluşturun:
- Microsoft Excel’de yeni bir çalışma kitabı açın.
- Biraz veri ekleyin.
- Sayfa kurulum seçeneklerini ayarlayın: Dosyaya sayfa yapısı seçeneklerini uygulayın. Yeni seçenekler uygulanmadan önce, varsayılan seçeneklerin ekran görüntüsü aşağıdadır.
Varsayılan sayfa kurulum seçenekleri. |
---|
![]() |
- Aspose.Cells’i indirin ve yükleyin:
- İndirmek .Net için Aspose.Cells.
- Geliştirme bilgisayarınıza kurun. Tüm Aspose bileşenleri kurulduğunda değerlendirme modunda çalışır. Değerlendirme modunun zaman sınırı yoktur ve yalnızca üretilen belgelere filigran ekler.
- Bir proje oluşturun:
- Visual Studio’yu başlatın. Açık.
- Yeni bir konsol uygulaması oluşturun. Bu örnek, bir C# konsol uygulamasını gösterecektir, ancak VB.NET’i de kullanabilirsiniz.
- Referans ekle:
- Bu örnek Aspose.Cells’i kullanır, bu nedenle projeye o bileşene bir referans ekleyin. Örneğin: …\Program Dosyaları\Aspose\Aspose.Cells\Bin\Net1.0\Aspose.Cells.dll
- API’i çağıran uygulamayı yazın:
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Open the template workbook | |
Workbook workbook = new Workbook(dataDir + "CustomerReport.xlsx"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Setting the orientation to Portrait | |
worksheet.PageSetup.Orientation = PageOrientationType.Portrait; | |
// Setting the scaling factor to 100 | |
// worksheet.PageSetup.Zoom = 100; | |
// OR Alternately you can use Fit to Page Options as under | |
// Setting the number of pages to which the length of the worksheet will be spanned | |
worksheet.PageSetup.FitToPagesTall = 1; | |
// Setting the number of pages to which the width of the worksheet will be spanned | |
worksheet.PageSetup.FitToPagesWide = 1; | |
// Setting the paper size to A4 | |
worksheet.PageSetup.PaperSize = PaperSizeType.PaperA4; | |
// Setting the print quality of the worksheet to 1200 dpi | |
worksheet.PageSetup.PrintQuality = 1200; | |
//Setting the first page number of the worksheet pages | |
worksheet.PageSetup.FirstPageNumber = 2; | |
// Save the workbook | |
workbook.Save(dataDir + "PageSetup_out.xlsx"); |
Yazdırma seçeneklerini ayarlama
Sayfa yapısı ayarları ayrıca, kullanıcıların çalışma sayfası sayfalarının nasıl yazdırılacağını denetlemesine olanak tanıyan çeşitli yazdırma seçenekleri (sayfa seçenekleri olarak da adlandırılır) sağlar. Kullanıcıların şunları yapmasına izin verir:
- Bir çalışma sayfasının belirli bir yazdırma alanını seçin.
- Başlıkları yazdırın.
- Kılavuz çizgilerini yazdırın.
- Satır/sütun başlıklarını yazdırın.
- Taslak kalitesine ulaşın.
- Yorumları yazdırın.
- Yazdırma hücresi hataları.
- Sayfa sıralamasını tanımlayın.
Aşağıdaki örnek, yukarıdaki örnekte oluşturulan dosyaya (PageSetup.xls) yazdırma seçeneklerini uygular. Aşağıdaki ekran görüntüsü, yeni seçenekler uygulanmadan önceki varsayılan yazdırma seçeneklerini gösterir.
Giriş belgesi |
---|
![]() |
Kodun çalıştırılması yazdırma seçeneklerini değiştirir. |
Çıktı dosyası |
---|
![]() |
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Open the template workbook | |
Workbook workbook = new Workbook(dataDir + "PageSetup.xlsx"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.Worksheets[0]; | |
PageSetup pageSetup = worksheet.PageSetup; | |
// Specifying the cells range (from A1 cell to E30 cell) of the print area | |
pageSetup.PrintArea = "A1:E30"; | |
// Defining column numbers A & E as title columns | |
pageSetup.PrintTitleColumns = "$A:$E"; | |
// Defining row numbers 1 as title rows | |
pageSetup.PrintTitleRows = "$1:$2"; | |
// Allowing to print gridlines | |
pageSetup.PrintGridlines = true; | |
// Allowing to print row/column headings | |
pageSetup.PrintHeadings = true; | |
// Allowing to print worksheet in black & white mode | |
pageSetup.BlackAndWhite = true; | |
// Allowing to print comments as displayed on worksheet | |
pageSetup.PrintComments = PrintCommentsType.PrintInPlace; | |
// Allowing to print worksheet with draft quality | |
pageSetup.PrintDraft = true; | |
// Allowing to print cell errors as N/A | |
pageSetup.PrintErrors = PrintErrorsType.PrintErrorsNA; | |
// Setting the printing order of the pages to over then down | |
pageSetup.Order = PrintOrderType.OverThenDown; | |
// Save the workbook | |
workbook.Save(dataDir + "PageSetup_Print_out.xlsx"); |