Satırları ve Sütunları Otomatik Sığdır

Otomatik Uydurma

Aspose.Cells bir sağlarÇalışma kitabıMicrosoft Excel dosyasını temsil eden sınıf. buÇalışma kitabısınıf bir içerirçalışma sayfalarıbir Excel dosyasındaki her çalışma sayfasına erişim sağlayan koleksiyon. Bir çalışma sayfası şununla temsil edilir:Çalışma kağıdı sınıf. buÇalışma kağıdı class, bir çalışma sayfasını yönetmek için çok çeşitli özellikler ve yöntemler sağlar. Bu makale,Çalışma kağıdısatırları veya sütunları otomatik sığdırmak için sınıf.

Satırı Otomatik Sığdır - Basit

Bir satırın genişliğini ve yüksekliğini otomatik olarak boyutlandırmak için en doğrudan yaklaşım,Çalışma kağıdı sınıfSatırı Otomatik Sığdır yöntem. buSatırı Otomatik Sığdıryöntem, parametre olarak (yeniden boyutlandırılacak satırın) bir satır dizinini alır.

// 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);
string InputPath = dataDir + "Book1.xlsx";
// Creating a file stream containing the Excel file to be opened
FileStream fstream = new FileStream(InputPath, FileMode.Open);
// Opening the Excel file through the file stream
Workbook workbook = new Workbook(fstream);
// Accessing the first worksheet in the Excel file
Worksheet worksheet = workbook.Worksheets[0];
// Auto-fitting the 3rd row of the worksheet
worksheet.AutoFitRow(1);
// Saving the modified Excel file
workbook.Save(dataDir + "output.xlsx");
// Closing the file stream to free all resources
fstream.Close();

Cells aralığında AutoFit Row

Bir satır birçok sütundan oluşur. Aspose.Cells, geliştiricilerin aşırı yüklenmiş bir sürümünü çağırarak satırdaki bir hücre aralığındaki içeriğe dayalı olarak bir satırı otomatik olarak sığdırmasına olanak tanır.Satırı Otomatik Sığdıryöntem. Aşağıdaki parametreleri alır:

  • Satır dizini, otomatik sığdırılacak satırın dizini.
  • İlk sütun dizini, satırın ilk sütununun dizini.
  • Son sütun dizini, satırın son sütununun dizini.

buSatırı Otomatik Sığdıryöntem, satırdaki tüm sütunların içeriğini kontrol eder ve ardından satıra otomatik olarak sığdırır.

// 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);
string InputPath = dataDir + "Book1.xlsx";
// Creating a file stream containing the Excel file to be opened
FileStream fstream = new FileStream(InputPath, FileMode.Open);
// Opening the Excel file through the file stream
Workbook workbook = new Workbook(fstream);
// Accessing the first worksheet in the Excel file
Worksheet worksheet = workbook.Worksheets[0];
// Auto-fitting the 3rd row of the worksheet
worksheet.AutoFitRow(1, 0, 5);
// Saving the modified Excel file
workbook.Save(dataDir + "output.xlsx");
// Closing the file stream to free all resources
fstream.Close();

Cells Aralığında Otomatik Sığdırma Sütunu

Bir sütun birçok satırdan oluşur. Aşırı yüklenmiş bir sürümünü çağırarak, sütundaki bir hücre aralığındaki içeriğe dayalı olarak bir sütunu otomatik olarak sığdırmak mümkündür.Otomatik Sığdırma Sütunuaşağıdaki parametreleri alan yöntem:

  • Sütun diziniotomatik olarak sığdırılacak sütunun dizini.
  • İlk satır dizini, sütunun ilk satırının dizini.
  • Son satır dizini, sütunun son satırının dizini.

buOtomatik Sığdırma Sütunuyöntem, sütundaki tüm satırların içeriğini kontrol eder ve ardından sütunu otomatik olarak sığdırır.

// 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);
string InputPath = dataDir + "Book1.xlsx";
// Creating a file stream containing the Excel file to be opened
FileStream fstream = new FileStream(InputPath, FileMode.Open);
// Opening the Excel file through the file stream
Workbook workbook = new Workbook(fstream);
// Accessing the first worksheet in the Excel file
Worksheet worksheet = workbook.Worksheets[0];
// Auto-fitting the Column of the worksheet
worksheet.AutoFitColumn(4, 4, 6);
// Saving the modified Excel file
workbook.Save(dataDir + "output.xlsx");
// Closing the file stream to free all resources
fstream.Close();

Birleştirilmiş Cells için Satırları Otomatik Sığdır

Aspose.Cells ile, kullanılarak birleştirilmiş hücreler için bile satırları otomatik sığdırmak mümkündür.Otomatik Sığdırma Seçenekleri API. Otomatik Sığdırma Seçeneklerisınıf sağlarAutoFitMergedCellsType satırları birleştirilmiş hücrelere otomatik sığdırmak için kullanılabilen özellik.AutoFitMergedCellsTypekabul ederAutoFitMergedCellsType aşağıdaki üyelere sahip numaralandırılabilir.

  • Yok: Birleştirilmiş hücreleri yok sayın.
  • FirstLine: Yalnızca ilk satırın yüksekliğini genişletir.
  • LastLine: Yalnızca son satırın yüksekliğini genişletir.
  • EveryLine: Yalnızca her satırın yüksekliğini genişletir.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
//Output directory
string outputDir = RunExamples.Get_OutputDirectory();
// Instantiate a new Workbook
Workbook wb = new Workbook();
// Get the first (default) worksheet
Worksheet _worksheet = wb.Worksheets[0];
// Create a range A1:B1
Range range = _worksheet.Cells.CreateRange(0, 0, 1, 2);
// Merge the cells
range.Merge();
// Insert value to the merged cell A1
_worksheet.Cells[0, 0].Value = "A quick brown fox jumps over the lazy dog. A quick brown fox jumps over the lazy dog....end";
// Create a style object
Aspose.Cells.Style style = _worksheet.Cells[0, 0].GetStyle();
// Set wrapping text on
style.IsTextWrapped = true;
// Apply the style to the cell
_worksheet.Cells[0, 0].SetStyle(style);
// Create an object for AutoFitterOptions
AutoFitterOptions options = new AutoFitterOptions();
// Set auto-fit for merged cells
options.AutoFitMergedCellsType = AutoFitMergedCellsType.EachLine;
// Autofit rows in the sheet(including the merged cells)
_worksheet.AutoFitRows(options);
// Save the Excel file
wb.Save(outputDir + "AutofitRowsforMergedCells.xlsx");

Bilmeniz Önemli

ileri konular