Spire.XLS for .NET设置Excel单元格文本自动换行

作者:控件中国网   出处:控件中国网   2015-09-07 14:16:51   阅读:33

在Excel使用当中,当单元格的文本超过该列宽度时,希望文本能自动换行显示,Spire.XLS for .NET是一款类似Excel的文档处理控件,完全使用代码实现Excel的功能,该控件可以帮助开发人员轻松实现单元格文本的自动换行显示,具体如下:

wrapunwraptext.jpg

using Spire.XLS;

namespace wrap

{

    class Program

    {

        static void Main(string[] args)

        {

            //Create a new workbook;

            Workbook workbook = new Workbook();

            Worksheet sheet = workbook.Worksheets[0];

 

 

            //Wrap the excel text;

            sheet.Range["C1"].Text = "e-iceblue is in facebook and welcome to like us";

            sheet.Range["C1"].Style.WrapText = true;

            sheet.Range["D1"].Text = "e-iceblue is in twitter and welcome to follow us";

            sheet.Range["D1"].Style.WrapText=  true;

 

 

            //Unwrap the excel text;

            sheet.Range["C2"].Text = "http://www.facebook.com/pages/e-iceblue/139657096082266";

            sheet.Range["C2"].Style.WrapText= false;

            sheet.Range["D2"].Text = "https://twitter.com/eiceblue";

            sheet.Range["D2"].Style.WrapText = false;

 

 

            //set the text color of Range["C1:D1"]

            sheet.Range["C1:D1"].Style.Font.Size = 15;

            sheet.Range["C1:D1"].Style.Font.Color = Color.Blue;

            //set the text color of Range["C2:D2"]

            sheet.Range["C2:D2"].Style.Font.Size = 15;

            sheet.Range["C2:D2"].Style.Font.Color = Color.DeepSkyBlue;

 

            // Save the project;

            workbook.SaveToFile("sample.xls", ExcelVersion.Version97to2003);

            System.Diagnostics.Process.Start(workbook.FileName);

 

        }

    }

}

Copyright© 2006-2015 ComponentCN.com all rights reserved.重庆磐岩科技有限公司(控件中国网) 版权所有 渝ICP备12000264号 法律顾问:元炳律师事务所
客服软件
live chat