本文整理汇总了C#中ApplicationClass.get_Range方法的典型用法代码示例。如果您正苦于以下问题:C# ApplicationClass.get_Range方法的具体用法?C# ApplicationClass.get_Range怎么用?C# ApplicationClass.get_Range使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ApplicationClass
的用法示例。
在下文中一共展示了ApplicationClass.get_Range方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExportToExcel
public static void ExportToExcel(IDataTable<DataRow> data, string filename,Protocol.Structure.WaitObject wt)
{
if (data == null)
return;
var excel = new ApplicationClass();
if (excel == null)
throw new Exception("Excel无法启动");
int rowNum = data.RowCount;
string[] columns = data.GetColumnsList();
int columnNum = columns.Length;
wt.Flags = new int[1];
wt.Max = rowNum * columnNum;
int rowIndex = 1;
int columnIndex = 0;
var book = excel.Application.Workbooks.Add(true);
try
{
foreach (var column in columns)
{
columnIndex++;
excel.Cells[rowIndex, columnIndex] = column;
if (data.GetColumnType(column) == typeof(string))
excel.get_Range(excel.Cells[rowIndex + 1, columnIndex], excel.Cells[rowNum + 1, columnIndex]).NumberFormatLocal = "@";
}
for (int i = 0; i < rowNum; i++)
{
rowIndex++;
columnIndex = 0;
for (int j = 0; j < columnNum; j++)
{
columnIndex++;
excel.Cells[rowIndex, columnIndex] = data[i,columns[j]];
wt.Flags[0]++;
}
}
excel.DisplayAlerts = false;
excel.AlertBeforeOverwriting = false;
book.SaveCopyAs(filename);
}
catch (Exception ex)
{
throw ex;
}
finally
{
book.Close(false);
book = null;
excel.Quit();
excel = null;
}
}
示例2: exporta_a_excel_categoria
public void exporta_a_excel_categoria()
{
ApplicationClass class2 = new ApplicationClass();
class2.Application.Workbooks.Add(true);
int num = 0;
int numC = 0;
pBar1.Minimum = 1;
pBar1.Maximum = dataGridView5.RowCount * dataGridView5.ColumnCount;
pBar1.Value = 1;
pBar1.Step = 1;
foreach (DataGridViewColumn column in this.dataGridView5.Columns)
{
class2.Cells[1, 1] = cmb_variedad.Text.Trim();
num++;
class2.Cells[1, num] = column.Name;
class2.get_Range("A1", "GF1").Interior.ColorIndex = 9;
class2.get_Range("A1", "GF1").Font.ColorIndex = 2;
}
foreach (DataGridViewColumn column in this.dataGridView6.Columns)
{
class2.Cells[10, 1] = cmb_variedad.Text.Trim();
numC++;
class2.Cells[10, numC] = column.Name;
class2.get_Range("A10", "GF10").Interior.ColorIndex = 9;
class2.get_Range("A10", "GF10").Font.ColorIndex = 2;
}
int num22 = 0;
foreach (DataGridViewRow row in (IEnumerable)this.dataGridView5.Rows)
{
num22++;
num = 0;
foreach (DataGridViewColumn column2 in this.dataGridView6.Columns)
{
num++;
class2.Cells[num22 + 1, num] = row.Cells[column2.Name].Value;
pBar1.PerformStep();
label2.Text = "Proceso :" + pBar1.Value.ToString() + "/" + (dataGridView5.RowCount * dataGridView5.ColumnCount).ToString();
}
}
int num2 =9;
foreach (DataGridViewRow row in (IEnumerable)this.dataGridView6.Rows)
{
num2++;
num= 0;
foreach (DataGridViewColumn column2 in this.dataGridView6.Columns)
{
num++;
class2.Cells[num2+1, num] = row.Cells[column2.Name].Value;
pBar1.PerformStep();
}
}
class2.Visible = true;
((Worksheet)class2.ActiveSheet).Name = cmb_variedad.Text.Trim();
((Worksheet)class2.ActiveSheet).Activate();
}
示例3: exporta_a_excel
public void exporta_a_excel()
{
ApplicationClass class2 = new ApplicationClass();
class2.Application.Workbooks.Add(true);
int num = 0;
pBar1.Minimum = 1;
pBar1.Maximum = dataGridView4.RowCount * dataGridView4.ColumnCount;
pBar1.Value = 1;
pBar1.Step = 1;
foreach (DataGridViewColumn column in this.dataGridView4.Columns)
{
class2.Cells[1, 1] = cmb_variedad.Text.Trim();
if (column.Name.ToString() != "cod")
{
num++;
class2.Cells[1, num] = column.Name;
class2.get_Range("A1", "H1").Interior.ColorIndex = 9;
class2.get_Range("A1", "H1").Font.ColorIndex = 2;
class2.get_Range("A10", "H10").Interior.ColorIndex = 56;
class2.get_Range("A10", "H10").Font.ColorIndex = 2;
class2.get_Range("H1", "H10").Interior.ColorIndex = 56;
class2.get_Range("H1", "H10").Font.ColorIndex = 2;
class2.get_Range("A1", "H1").Borders.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Black);
}
}
int num2 = 0;
foreach (DataGridViewRow row in (IEnumerable)this.dataGridView4.Rows)
{
num2++;
num = 0;
foreach (DataGridViewColumn column2 in this.dataGridView4.Columns)
{
if (column2.Name.ToString() != "cod")
{
num++;
class2.Cells[num2 + 1, num] = row.Cells[column2.Name].Value;
pBar1.PerformStep();
}
}
}
class2.Visible = true;
((Worksheet)class2.ActiveSheet).Name = cmb_variedad.Text.Trim();
((Worksheet)class2.ActiveSheet).Activate();
}
示例4: exporta_a_excel
public void exporta_a_excel()
{
pBar1.Visible = true;
ApplicationClass class2 = new ApplicationClass();
class2.Application.Workbooks.Add(true);
int num = 0;
pBar1.Minimum = 1;
pBar1.Maximum = dataGridView4.RowCount * dataGridView4.ColumnCount;
pBar1.Value = 1;
pBar1.Step = 1;
foreach (DataGridViewColumn column in this.dataGridView4.Columns)
{
class2.Cells[1, 1] = cmb_variedad.Text.Trim();
num++;
class2.Cells[1, num] = column.Name;
class2.get_Range("A1", "L1").Interior.ColorIndex = 9;
class2.get_Range("A1", "L1").Font.ColorIndex = 2;
}
int num2 = 0;
foreach (DataGridViewRow row in (IEnumerable)this.dataGridView4.Rows)
{
num2++;
num = 0;
foreach (DataGridViewColumn column2 in this.dataGridView4.Columns)
{
num++;
class2.Cells[num2 + 1, num] = row.Cells[column2.Name].Value;
pBar1.PerformStep();
}
}
class2.Visible = true;
((Worksheet)class2.ActiveSheet).Name = cmb_variedad.Text.Trim();
((Worksheet)class2.ActiveSheet).Activate();
}