Envoltura Cell Texto

Envoltura Cell Texto

Para crear una hoja de cálculo con dos celdas, una con texto ajustado y otra sin:

  1. Configure la hoja de trabajo:
  2. Cree un libro de trabajo.
  3. Acceda a la primera hoja de trabajo.
  4. Añadir texto:
  5. Agregue texto a la celda A1.
  6. Agregue texto ajustado a la celda A5.
  7. Guarde la hoja de cálculo.

Los ejemplos de código a continuación muestran cómo realizar estos pasos usandoVSTO con C# o Visual Basic. Ejemplos de código que muestran cómo hacer lo mismo usandoAspose.Cells for .NET, nuevamente utilizando C# o Visual Basic, siga inmediatamente después.

Ejecutar el código da como resultado una hoja de cálculo con dos celdas, una que tiene texto que no se ha ajustado y otra que tiene:

Texto de celda de ajuste de salida con VSTO

todo:imagen_alternativa_texto

Texto de celda de envoltura de salida con Aspose.Cells for .NET

todo:imagen_alternativa_texto

Envolviendo Cell texto usando VSTO

C#

 //Note: To help you better, the code uses full namespacing

void WrappingCellText()

{

    //Access vsto application

    Microsoft.Office.Interop.Excel.Application app = Globals.ThisAddIn.Application;

    //Access workbook 

    Microsoft.Office.Interop.Excel.Workbook workbook = app.ActiveWorkbook;

    //Access worksheet 

    Microsoft.Office.Interop.Excel.Worksheet m_sheet = workbook.Worksheets[1];

    //Access vsto worksheet

    Microsoft.Office.Tools.Excel.Worksheet sheet = Globals.Factory.GetVstoObject(m_sheet);

    //Place some text in cell A1 without wrapping

    Microsoft.Office.Interop.Excel.Range cellA1 = sheet.Cells.get_Range("A1");

    cellA1.Value = "Sample Text Unwrapped";

    //Place some text in cell A5 with wrapping

    Microsoft.Office.Interop.Excel.Range cellA5 = sheet.Cells.get_Range("A5");

    cellA5.Value = "Sample Text Wrapped";

    cellA5.WrapText = true;

    //Save the workbook

    workbook.SaveAs("f:\\downloads\\OutputVsto.xlsx");

    //Quit the application

    app.Quit();

}

Envolviendo Cell Texto usando Aspose.Cells for .NET

C#

 void WrappingCellText()

{

    //Create workbook

    Workbook workbook = new Workbook();

    //Access worksheet

    Worksheet worksheet = workbook.Worksheets[0];

    //Place some text in cell A1 without wrapping

    Cell cellA1 = worksheet.Cells["A1"];

    cellA1.PutValue("Some Text Unwrapped");

    //Place some text in cell A5 wrapping

    Cell cellA5 = worksheet.Cells["A5"];

    cellA5.PutValue("Some Text Wrapped");

    Style style = cellA5.GetStyle();

    style.IsTextWrapped = true;

    cellA5.SetStyle(style);

    //Autofit rows

    worksheet.AutoFitRows();

    //Save the workbook

    workbook.Save("f:\\downloads\\OutputAspose.xlsx", SaveFormat.Xlsx);

}