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


C# List.CopyTo方法代码示例

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


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

示例1: ExportListViews2Excel

        //string idBill, string idUser, string idCustomer, DateTime time, long subtractMoney, long totalMoney)
        public static bool ExportListViews2Excel(string sSheetName, string sPath, List<ListView> lv)
        {
            try
            {
                // Khởi động chtr Excell
                exApp = new COMExcel.Application();

                // Thêm file temp xls
                exBook = exApp.Workbooks.Add(
                          COMExcel.XlWBATemplate.xlWBATWorksheet);

                // Lấy sheet 1.
                COMExcel.Worksheet exSheet = (COMExcel.Worksheet)exBook.Worksheets[1];

                exSheet.Activate();
                exSheet.Name = sSheetName;

                List<int> list_iMaxLength = new List<int>(); //Gia tri max de so sanh AutoFit column

                int iRowFit = 1;
                int iColumnFit = 1;
                bool isNewMaxLength = true;

                int rowIndex = 0;

                foreach (ListView listView in lv)
                {
                    int[] listOldMaxLength = new int[list_iMaxLength.Count];
                    list_iMaxLength.CopyTo(listOldMaxLength);
                    list_iMaxLength.Clear();

                    for (int iColumn = 0; iColumn < listView.Columns.Count; iColumn++)
                    {
                        COMExcel.Range r = (COMExcel.Range)exSheet.Cells[rowIndex + 1, iColumn + 1];

                        r.Font.Bold = true;
                        r.Value2 = listView.Columns[iColumn].Text.ToString();
                        //r.BorderAround(COMExcel.XlLineStyle.xlContinuous, COMExcel.XlBorderWeight.xlThin, COMExcel.XlColorIndex.xlColorIndexAutomatic, 1);

                        if (iColumn < listOldMaxLength.Length && listView.Columns[iColumn].Text.Length < listOldMaxLength[iColumn])
                        {
                            list_iMaxLength.Add(listOldMaxLength[iColumn]);
                        }
                        else
                        {
                            list_iMaxLength.Add(listView.Columns[iColumn].Text.Length);

                            COMExcel.Range rFit = (COMExcel.Range)exSheet.Cells[rowIndex + 1, iColumn + 1];
                            rFit.Columns.AutoFit();
                        }
                    }

                    //rowIndex += 1;

                    for (int iColumn = 0; iColumn < listView.Columns.Count; iColumn++)
                    {
                        iRowFit = rowIndex + 1;
                        iColumnFit = iColumn + 1;

                        for (int iRow = rowIndex; iRow < listView.Items.Count + rowIndex; iRow++)
                        {
                            COMExcel.Range r = (COMExcel.Range)exSheet.Cells[iRow + 2, iColumn + 1];

                            r.Value2 = listView.Items[iRow - rowIndex].SubItems[iColumn].Text.ToString();
                            //r.BorderAround(COMExcel.XlLineStyle.xlContinuous, COMExcel.XlBorderWeight.xlThin, COMExcel.XlColorIndex.xlColorIndexAutomatic, 1);

                            if (listView.Items[iRow - rowIndex].SubItems[iColumn].Text.Length > list_iMaxLength[iColumn])
                            {
                                list_iMaxLength[iColumn] = listView.Items[iRow - rowIndex].SubItems[iColumn].Text.Length;

                                iRowFit = iRow + 2;
                                iColumnFit = iColumn + 1;

                                isNewMaxLength = true;
                            }
                        }

                        if (isNewMaxLength)
                        {
                            COMExcel.Range rFit = (COMExcel.Range)exSheet.Cells[iRowFit, iColumnFit];
                            rFit.Columns.AutoFit();

                            isNewMaxLength = false;
                        }
                    }

                    rowIndex += listView.Items.Count;
                    rowIndex += 1;
                }

                exApp.Visible = false;

                exBook.SaveAs(sPath, COMExcel.XlFileFormat.xlWorkbookNormal,
                                null, null, false, false,
                                COMExcel.XlSaveAsAccessMode.xlExclusive,
                                false, false, false, false, false);
                exBook.Close(false, false, false);
                exApp.Quit();

//.........这里部分代码省略.........
开发者ID:vuchannguyen,项目名称:lg-py,代码行数:101,代码来源:Office_Function.cs


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