簡體   English   中英

如何使用C#在Excel文本框中設置多行文本

[英]How could I set multi-line text in an Excel textbox using C#

這是我的代碼:

using Excel = Microsoft.Office.Interop.Excel;

private void button1_Click(object sender, EventArgs e)
{
    Excel.Application xlApp = new Excel.Application();
    Excel.Workbook wb = xlApp.Workbooks.Add(System.Type.Missing);
    Excel.Worksheet ws = (Excel.Worksheet)wb.Sheets[1];
    xlApp.Visible = true;

    Excel.Shape textBox = ws.Shapes.AddTextbox(
        Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal,
        10 + 10 + 10, 36, 600, 100);
    textBox.TextFrame.Characters(System.Type.Missing, System.Type.Missing).Text
        = "testing";

    xlApp.ActiveWindow.Activate();
    xlApp.UserControl = true;
    ws = null;
    wb = null;
    xlApp = null;
}

但是使用這段代碼我只能添加一行文本“testing”:

---------------------------------
|Testing                        |
|                               |
|                               |
---------------------------------

現在我要添加3行文本,如下所示:

---------------------------------
|Test1                          |
|Test2                          |
|Test3                          |
---------------------------------

來人幫幫我?

System.Environment.NewLine可能是您要分離3個字符串的常量。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM