当前位置: 首页>>代码示例>>C#>>正文


C# Worksheet.AutoFitColumns方法代码示例

本文整理汇总了C#中Worksheet.AutoFitColumns方法的典型用法代码示例。如果您正苦于以下问题:C# Worksheet.AutoFitColumns方法的具体用法?C# Worksheet.AutoFitColumns怎么用?C# Worksheet.AutoFitColumns使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Worksheet的用法示例。


在下文中一共展示了Worksheet.AutoFitColumns方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DataGridViewExport

        public DataGridViewExport(DataGridView dgv)
        {
            _workbook = new Workbook();
            _workbook.Worksheets.Clear();
            _worksheet = _workbook.Worksheets[_workbook.Worksheets.Add()];
            _worksheet.Name = "Sheet1";
            _colIndexes = new List<int>();

            int sheetRowIndex = 0;
            int sheetColIndex = 0;
            foreach (DataGridViewColumn col in dgv.Columns)
            {
                if (col.Visible == false) continue;
                _colIndexes.Add(col.Index);
                _worksheet.Cells[sheetRowIndex, sheetColIndex++].PutValue(col.HeaderText);
            }

            foreach (DataGridViewRow row in dgv.Rows)
            {
                sheetRowIndex++;
                sheetColIndex = 0;
                foreach (int colIndex in _colIndexes)
                    _worksheet.Cells[sheetRowIndex, sheetColIndex++].PutValue("" + row.Cells[colIndex].Value);
            }

            _worksheet.AutoFitColumns();
        }
开发者ID:ischool-desktop,项目名称:MOD_Club.General.Zizhu,代码行数:27,代码来源:DataGridViewExport.cs

示例2: ImportTwoDimensionArray

        private void ImportTwoDimensionArray(Worksheet sheet)
        {
            //Get the cells collection in the worksheet
            Cells cells = sheet.Cells;

            //Put a string value into a cell
            sheet.Cells["A1"].PutValue("Import a two-dimension object Array");

            //Get Style Object
            Aspose.Cells.Style style = cells["A1"].GetStyle();

            //the font text is set to bold
            style.Font.IsBold = true;

            //Apply style to the cell
            cells["A1"].SetStyle(style);

            //Create a multi-dimensional array and fill some values
            object[,] objs = new object[2, 3];
            objs[0, 0] = "Product ID";
            objs[0, 1] = 1;
            objs[0, 2] = 2;
            objs[1, 0] = "Product Name";
            objs[1, 1] = "Aniseed Syrup";
            objs[1, 2] = "Boston Crab Meat";
            //Import the multi-dimensional array to the sheet cells
            sheet.Cells.ImportTwoDimensionArray(objs, 1, 0);
            //Autofit the sheet cells
            sheet.AutoFitColumns();
        }
开发者ID:babar-raza,项目名称:Aspose_Cells_NET,代码行数:30,代码来源:importing-data.aspx.cs

示例3: ImportObjectArray

        private void ImportObjectArray(Worksheet sheet)
        {
            //Get the cells collection in the worksheet
            Cells cells = sheet.Cells;

            //Put a string value into a cell
            sheet.Cells["A1"].PutValue("Import an object Array");

            //Get Style Object
            Aspose.Cells.Style style = cells["A1"].GetStyle();

            //the font text is set to bold
            style.Font.IsBold = true;

            //Apply style to the cell
            cells["A1"].SetStyle(style);

            //Create an object array and fill it with some values
            object[] obj = { "Tom", "John", "kelly", 1, 2, 2.8, 5.16, true, false };

            //Import the object array to the sheet cells
            sheet.Cells.ImportObjectArray(obj, 1, 0, false);

            //Autofit all the columns in the sheet
            sheet.AutoFitColumns();
        }
开发者ID:babar-raza,项目名称:Aspose_Cells_NET,代码行数:26,代码来源:importing-data.aspx.cs

示例4: ImportFromDataReader

        private void ImportFromDataReader(Worksheet sheet)
        {
            //Get the cells collection in the worksheet
            Cells cells = sheet.Cells;

            //Put the string value into a cell
            sheet.Cells["A1"].PutValue("Import from DataReader");

            //Get Style Object
            Aspose.Cells.Style style = cells["A1"].GetStyle();

            //the font text is set to bold
            style.Font.IsBold = true;

            //Apply style to the cell
            cells["A1"].SetStyle(style);

            string path = Server.MapPath("~");
            path = path.Substring(0, path.LastIndexOf("\\")) + "\\Database\\Northwind.mdb";
            string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path;
            string sql = "SELECT Country,EmployeeID,FirstName,LastName FROM Employees ORDER BY Country,EmployeeID";

            //Define connection scope
            using (OleDbConnection conn = new OleDbConnection(connectionString))
            {
                //Create command object
                OleDbCommand command = new OleDbCommand(sql, conn);

                //Open connection
                conn.Open();

                //Create and fill data reader object
                OleDbDataReader reader;
                reader = command.ExecuteReader();

                //Import the datareader object to the sheet cells
                sheet.Cells.ImportDataReader(reader, true, 1, 0, false);

                //sheet.Cells.ImportFromDataReader(reader, true, 1, 0, false);

                // Always call Close when done reading.
                reader.Close();
            }

            //Autofit all the columns in the sheet
            sheet.AutoFitColumns();
        }
开发者ID:babar-raza,项目名称:Aspose_Cells_NET,代码行数:47,代码来源:importing-data.aspx.cs

示例5: ImportDataView

        private void ImportDataView(Worksheet sheet)
        {
            //Get the cells collection in the worksheet
            Cells cells = sheet.Cells;

            //Put a string value into a cell
            sheet.Cells["A1"].PutValue("Import a DataView");

            //Get Style Object
            Aspose.Cells.Style style = cells["A1"].GetStyle();

            //the font text is set to bold
            style.Font.IsBold = true;

            //Apply style to the cell
            cells["A1"].SetStyle(style);

            //Create a datatable and add three columns to it
            DataTable dataTable = new DataTable("Products");
            dataTable.Columns.Add("Product ID", typeof(Int32));
            dataTable.Columns.Add("Product Name", typeof(string));
            dataTable.Columns.Add("Units In Stock", typeof(Int32));

            //Add the first record to it
            DataRow dr = dataTable.NewRow();
            dr[0] = 1;
            dr[1] = "Aniseed Syrup";
            dr[2] = 15;
            dataTable.Rows.Add(dr);

            //Add the second record to it
            dr = dataTable.NewRow();
            dr[0] = 2;
            dr[1] = "Boston Crab Meat";
            dr[2] = 123;
            dataTable.Rows.Add(dr);

            //Import the dataview to the sheet cells
            sheet.Cells.ImportDataView(dataTable.DefaultView, true, 1, 0, false);

            //Autofit all the columns in the sheet
            sheet.AutoFitColumns();
        }
开发者ID:babar-raza,项目名称:Aspose_Cells_NET,代码行数:43,代码来源:importing-data.aspx.cs


注:本文中的Worksheet.AutoFitColumns方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。