Satır ve Sütunları Biçimlendir

Satırlarla Çalışmak

Satır Yüksekliğini Ayarlamak

Aspose.Cells for Python via .NET, Microsoft Excel dosyasını temsil eden Workbook sınıfını sağlar. Workbook sınıfı, Excel dosyasındaki her bir çalışma sayfasına erişim sağlayan bir WorksheetCollection içerir. Bir çalışma sayfası, Worksheet sınıfı ile temsil edilir. Worksheet sınıfı, çalışma sayfasındaki tüm hücreleri temsil eden bir Cells koleksiyonu sağlar.

Cells koleksiyonu, bir çalışma sayfasındaki satırları veya sütunları yönetmek için çeşitli yöntemler sağlar. Bunlardan bazıları aşağıda daha detaylı bir şekilde ele alınmıştır.

Bir Satırın Yüksekliğini Ayarlama

Tek bir satırın yüksekliğini, Cells koleksiyonunun set_row_height yöntemini çağırarak ayarlamak mümkündür. set_row_height yöntemi aşağıdaki parametreleri alır:

  • satır, yüksekliğini değiştirdiğiniz satırın dizini.
  • yükseklik, satıra uygulanacak yükseklik.
from aspose.cells import Workbook
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# The path to the documents directory.
dataDir = RunExamples.GetDataDir(".")
# Creating a file stream containing the Excel file to be opened
fstream = open(dataDir + "book1.xls", "rb")
# Instantiating a Workbook object
# Opening the Excel file through the file stream
workbook = Workbook(fstream)
# Accessing the first worksheet in the Excel file
worksheet = workbook.worksheets[0]
# Setting the height of the second row to 13
worksheet.cells.set_row_height(1, 13)
# Saving the modified Excel file
workbook.save(dataDir + "output.out.xls")
# Closing the file stream to free all resources
fstream.close()

Bir Çalışma Sayfasındaki Tüm Satırların Yüksekliğini Ayarlama

Geliştiriciler, çalışma sayfasındaki tüm satırlara aynı yüksekliği ayarlamak istiyorlarsa, bunu standard_height koleksiyonunun Cells özelliğini kullanarak yapabilirler.

Örnek:

from aspose.cells import Workbook
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# The path to the documents directory.
dataDir = RunExamples.GetDataDir(".")
# Creating a file stream containing the Excel file to be opened
fstream = open(dataDir + "book1.xls", "rb")
# Instantiating a Workbook object
# Opening the Excel file through the file stream
workbook = Workbook(fstream)
# Accessing the first worksheet in the Excel file
worksheet = workbook.worksheets[0]
# Setting the height of all rows in the worksheet to 15
worksheet.cells.standard_height = 15.0
# Saving the modified Excel file
workbook.save(dataDir + "output.out.xls")
# Closing the file stream to free all resources
fstream.close()

Sütunlarla Çalışmak

Bir Sütunun Genişliğini Ayarlama

Bir sütunun genişliğini, Cells koleksiyonunun set_column_width yöntemini çağırarak ayarlayabilirsiniz. set_column_width yöntemi aşağıdaki parametreleri alır:

  • sütun, genişliğini değiştirdiğiniz sütunun dizini.
  • genişlik, istenen sütun genişliği.
from aspose.cells import Workbook
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# The path to the documents directory.
dataDir = RunExamples.GetDataDir(".")
# Creating a file stream containing the Excel file to be opened
fstream = open(dataDir + "book1.xls", "rb")
# Instantiating a Workbook object
# Opening the Excel file through the file stream
workbook = Workbook(fstream)
# Accessing the first worksheet in the Excel file
worksheet = workbook.worksheets[0]
# Setting the width of the second column to 17.5
worksheet.cells.set_column_width(1, 17.5)
# Saving the modified Excel file
workbook.save(dataDir + "output.out.xls")
# Closing the file stream to free all resources
fstream.close()

Piksel cinsinden Sütun Genişliğini Ayarlama

Bir sütunun genişliğini, Cells koleksiyonunun set_column_width_pixel yöntemini çağırarak ayarlayabilirsiniz. set_column_width_pixel yöntemi aşağıdaki parametreleri alır:

  • sütun, genişliğini değiştirdiğiniz sütunun dizini.
  • piksel, istenen sütun genişliği piksel cinsinden.
from aspose.cells import Workbook
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# Source directory
sourceDir = RunExamples.Get_SourceDirectory()
outDir = RunExamples.Get_OutputDirectory()
# Load source Excel file
workbook = Workbook(sourceDir + "Book1.xlsx")
# Access first worksheet
worksheet = workbook.worksheets[0]
# Set the width of the column in pixels
worksheet.cells.set_column_width_pixel(7, 200)
workbook.save(outDir + "SetColumnWidthInPixels_Out.xlsx")

Bir Çalışma Sayfasındaki Tüm Sütunların Genişliğini Ayarlama

Çalışma sayfasındaki tüm sütunlara aynı genişliği ayarlamak için Cells koleksiyonunun standard_width özelliğini kullanın.

from aspose.cells import Workbook
from os import os, path
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# The path to the documents directory.
dataDir = RunExamples.GetDataDir(".")
# Create directory if it is not already present.
IsExists = path.isdir(dataDir)
if notIsExists:
os.makedirs(dataDir)
# Creating a file stream containing the Excel file to be opened
fstream = open(dataDir + "book1.xls", "rb")
# Instantiating a Workbook object
# Opening the Excel file through the file stream
workbook = Workbook(fstream)
# Accessing the first worksheet in the Excel file
worksheet = workbook.worksheets[0]
# Setting the width of all columns in the worksheet to 20.5
worksheet.cells.standard_width = 20.5
# Saving the modified Excel file
workbook.save(dataDir + "output.out.xls")
# Closing the file stream to free all resources
fstream.close()

Gelişmiş Konular