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


C# Workbook.get_Worksheets方法代码示例

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


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

示例1: DataTableToExcel

 public static bool DataTableToExcel(DataTable datatable, string filepath, out string error)
 {
     Exception exception;
     error = "";
     try
     {
         if (datatable == null)
         {
             error = "DataTableToExcel:datatable 为空";
             return false;
         }
         Workbook workbook = new Workbook();
         Worksheet worksheet = workbook.get_Worksheets().get_Item(0);
         Aspose.Cells.Cells cells = worksheet.get_Cells();
         int num = 0;
         foreach (DataRow row in datatable.Rows)
         {
             num++;
             try
             {
                 for (int i = 0; i < datatable.Columns.Count; i++)
                 {
                     if (row[i].GetType().ToString() == "System.Drawing.Bitmap")
                     {
                         Image image = (Image) row[i];
                         MemoryStream stream = new MemoryStream();
                         image.Save(stream, ImageFormat.Jpeg);
                         worksheet.get_Pictures().Add(num, i, stream);
                     }
                     else
                     {
                         cells.get_Item(num, i).PutValue(row[i]);
                     }
                 }
                 continue;
             }
             catch (Exception exception1)
             {
                 exception = exception1;
                 error = error + " DataTableToExcel: " + exception.Message;
                 continue;
             }
         }
         workbook.Save(filepath);
         return true;
     }
     catch (Exception exception2)
     {
         exception = exception2;
         error = error + " DataTableToExcel: " + exception.Message;
         return false;
     }
 }
开发者ID:windygu,项目名称:asxinyunet,代码行数:53,代码来源:AsposeExcelTools.cs

示例2: DataTableInsertToExcel

 public static bool DataTableInsertToExcel(DataTable datatable, ArrayList colNameList, string fromfile, out string error, int beginRow, int beginColumn)
 {
     error = "";
     if (datatable == null)
     {
         error = "DataTableToExcel:datatable 为空";
         return false;
     }
     Workbook workbook = new Workbook();
     workbook.Open(fromfile);
     Aspose.Cells.Cells cells = workbook.get_Worksheets().get_Item(0).get_Cells();
     int num = 0;
     foreach (DataRow row in datatable.Rows)
     {
         num++;
         try
         {
             cells.InsertRow(beginRow);
             for (int i = 0; i < colNameList.Count; i++)
             {
                 string str = colNameList[i].ToString();
                 int num3 = 0;
                 while (num3 < datatable.Columns.Count)
                 {
                     if (str == datatable.Columns[num3].ColumnName)
                     {
                         goto Label_00C4;
                     }
                     num3++;
                 }
                 continue;
             Label_00C4:
                 object obj1 = row[datatable.Columns[num3].ColumnName];
                 cells.get_Item(beginRow, beginColumn + i).PutValue(row[datatable.Columns[num3].ColumnName]);
             }
             continue;
         }
         catch (Exception exception)
         {
             error = error + " DataTableInsertToExcel: " + exception.Message;
             continue;
         }
     }
     workbook.Save(fromfile);
     return true;
 }
开发者ID:windygu,项目名称:asxinyunet,代码行数:46,代码来源:AsposeExcelTools.cs

示例3: ListsToExcelFile

 public static bool ListsToExcelFile(string filepath, IList[] lists, out string error)
 {
     error = "";
     Workbook workbook = new Workbook();
     Worksheet worksheet = workbook.get_Worksheets().get_Item(0);
     Aspose.Cells.Cells cells = worksheet.get_Cells();
     int num = 0;
     worksheet.get_Pictures().Clear();
     cells.Clear();
     IList[] listArray = lists;
     int index = 0;
 Label_003A:
     if (index < listArray.Length)
     {
         IList list = listArray[index];
         int num3 = 0;
         while (true)
         {
             if (num3 <= (list.Count - 1))
             {
                 try
                 {
                     Console.WriteLine(num3.ToString() + "  " + list[num3].GetType());
                     if (list[num3].GetType().ToString() == "System.Drawing.Bitmap")
                     {
                         Image image = (Image) list[num3];
                         MemoryStream stream = new MemoryStream();
                         image.Save(stream, ImageFormat.Jpeg);
                         worksheet.get_Pictures().Add(num, num3, stream);
                     }
                     else
                     {
                         cells.get_Item(num, num3).PutValue(list[num3]);
                     }
                 }
                 catch (Exception exception)
                 {
                     error = error + exception.Message;
                 }
             }
             else
             {
                 num++;
                 index++;
                 goto Label_003A;
             }
             num3++;
         }
     }
     workbook.Save(filepath);
     return true;
 }
开发者ID:windygu,项目名称:asxinyunet,代码行数:52,代码来源:AsposeExcelTools.cs

示例4: GetPicturesFromExcelFile

 public static bool GetPicturesFromExcelFile(string filepath, out Pictures[] pictures, out string error)
 {
     error = "";
     pictures = null;
     try
     {
         if (!File.Exists(filepath))
         {
             error = "文件不存在";
             pictures = null;
             return false;
         }
         Workbook workbook = new Workbook();
         workbook.Open(filepath);
         pictures = new Pictures[workbook.get_Worksheets().Count];
         for (int i = 0; i < workbook.get_Worksheets().Count; i++)
         {
             pictures[i] = workbook.get_Worksheets().get_Item(i).get_Pictures();
         }
         return true;
     }
     catch (Exception exception)
     {
         error = exception.Message;
         return false;
     }
 }
开发者ID:windygu,项目名称:asxinyunet,代码行数:27,代码来源:AsposeExcelTools.cs

示例5: ExcelFileToDataTables

 public static bool ExcelFileToDataTables(string filepath, out DataTable[] datatables, out string error)
 {
     error = "";
     datatables = null;
     int count = 0;
     try
     {
         if (!File.Exists(filepath))
         {
             error = "文件不存在";
             datatables = null;
             return false;
         }
         Workbook workbook = new Workbook();
         workbook.Open(filepath);
         count = workbook.get_Worksheets().Count;
         datatables = new DataTable[count];
         for (int i = 0; i < count; i++)
         {
             Worksheet worksheet = workbook.get_Worksheets().get_Item(i);
             datatables[i] = worksheet.get_Cells().ExportDataTable(0, 0, worksheet.get_Cells().get_MaxRow() + 1, worksheet.get_Cells().get_MaxColumn() + 1);
             Pictures pictures = worksheet.get_Pictures();
             if (pictures.Count > 0)
             {
                 string str = "";
                 if (!smethod_0(pictures, datatables[i], out datatables[i], out str))
                 {
                     error = error + str;
                 }
             }
         }
         return true;
     }
     catch (Exception exception)
     {
         error = exception.Message;
         return false;
     }
 }
开发者ID:windygu,项目名称:asxinyunet,代码行数:39,代码来源:AsposeExcelTools.cs

示例6: ExcelFileToDataTable

 public static bool ExcelFileToDataTable(string filepath, out DataTable datatable, int iFirstRow, int iFirstCol, int rowNum, int colNum, out string error)
 {
     error = "";
     datatable = null;
     try
     {
         if (!File.Exists(filepath))
         {
             error = "文件不存在";
             datatable = null;
             return false;
         }
         Workbook workbook = new Workbook();
         workbook.Open(filepath);
         Worksheet worksheet = workbook.get_Worksheets().get_Item(0);
         datatable = worksheet.get_Cells().ExportDataTable(iFirstRow, iFirstCol, rowNum + 1, colNum + 1);
         return true;
     }
     catch (Exception exception)
     {
         error = exception.Message;
         return false;
     }
 }
开发者ID:windygu,项目名称:asxinyunet,代码行数:24,代码来源:AsposeExcelTools.cs

示例7: DataTableToExcel2

 public static bool DataTableToExcel2(DataTable datatable, string filepath, out string error)
 {
     error = "";
     Workbook workbook = new Workbook();
     try
     {
         if (datatable == null)
         {
             error = "DataTableToExcel:datatable 为空";
             return false;
         }
         Style style = workbook.get_Styles().get_Item(workbook.get_Styles().Add());
         style.set_HorizontalAlignment(1);
         style.set_ForegroundColor(Color.FromArgb(0x99, 0xcc, 0));
         style.set_Pattern(1);
         style.get_Font().set_IsBold(true);
         int num = 0;
         int num2 = 0;
         while (num2 < datatable.Columns.Count)
         {
             DataColumn column = datatable.Columns[num2];
             string str = column.Caption ?? column.ColumnName;
             workbook.get_Worksheets().get_Item(0).get_Cells().get_Item(num, num2).PutValue(str);
             workbook.get_Worksheets().get_Item(0).get_Cells().get_Item(num, num2).set_Style(style);
             num2++;
         }
         num++;
         foreach (DataRow row in datatable.Rows)
         {
             for (num2 = 0; num2 < datatable.Columns.Count; num2++)
             {
                 workbook.get_Worksheets().get_Item(0).get_Cells().get_Item(num, num2).PutValue(row[num2].ToString());
             }
             num++;
         }
         for (int i = 0; i < datatable.Columns.Count; i++)
         {
             workbook.get_Worksheets().get_Item(0).AutoFitColumn(i, 0, 150);
         }
         workbook.get_Worksheets().get_Item(0).FreezePanes(1, 0, 1, datatable.Columns.Count);
         workbook.Save(filepath);
         return true;
     }
     catch (Exception exception)
     {
         error = error + " DataTableToExcel: " + exception.Message;
         return false;
     }
 }
开发者ID:windygu,项目名称:asxinyunet,代码行数:49,代码来源:AsposeExcelTools.cs


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