ラッピング Cell テキスト

ラッピング Cell テキスト

2 つのセル (折り返されたテキストのあるセルとないセル) を持つワークシートを作成するには:

  1. ワークシートを設定します。
  2. ワークブックを作成します。
  3. 最初のワークシートにアクセスします。
  4. テキストを追加:
  5. セル A1 にテキストを追加します。
  6. 折り返されたテキストをセル A5 に追加します。
  7. スプレッドシートを保存します。

以下のコード サンプルは、これらの手順を実行する方法を示しています。VSTO C# または Visual Basic で。を使用して同じことを行う方法を示すコード サンプルAspose.Cells for .NET、再び C# または Visual Basic を使用して、直後に続きます。

コードを実行すると、2 つのセルを含むスプレッドシートが作成されます。

VSTO で折り返しセル テキストを出力する

todo:画像_代替_文章

Aspose.Cells for .NET で折り返しセル テキストを出力する

todo:画像_代替_文章

VSTO を使用した Cell テキストの折り返し

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();

}

Aspose.Cells for .NET を使用した Cell テキストの折り返し

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);

}