本文整理汇总了C#中Library.List.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# List.Clear方法的具体用法?C# List.Clear怎么用?C# List.Clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Library.List
的用法示例。
在下文中一共展示了List.Clear方法的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();
//.........这里部分代码省略.........