简体   繁体   English

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

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

Here my code: 这是我的代码:

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

But with this code I only can add one line text "testing": 但是使用这段代码我只能添加一行文本“testing”:

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

Now I want to add 3 line text, like this: 现在我要添加3行文本,如下所示:

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

Somebody help me? 来人帮帮我?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C#-将多行文本框保存到文本文件 - C# - Save a Multi-Line Textbox to a text file 如何在文本框(C#)中将多行(fasta格式)另存为一行? - How do I save a multi-line(fasta format) as one line in textbox (C#)? 如何在C#中将大型多行文本分配到字符串中? - How to assign large multi-line text into string in C#? 如何将多行文本框作为一行保存到文本文件中? - How do I save a multi-line textbox as one line to a text file? 如何以可读格式和asp.net C#显示多行文本框中的文件内容 - how to display the contents of file in multi-line textbox in readable format and in asp.net C# 在使用C#XmlWriter创建的XML excel文档的单元格中显示多行文本值 - show multi-line text value in cells of an XML excel document made with C# XmlWriter 如何将 DataGridView 文本框列设置为多行? - How to set DataGridView textbox column to multi-line? 使用多行Excel单元格进入C#程序 - Working with a multi-line Excel Cell into a C# Program 正则表达式匹配以提取多行文本区域(C#) - Regex matching on to extract multi-line text regions (C#) C#如何将此代码从多行文本修改为从右到左移动的选框文本上的标签? - C# How to fix this code from multi-line text to label on marquee text moving right to left?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM