本文整理汇总了C#中Microsoft.Office.Interop.Excel.Range类的典型用法代码示例。如果您正苦于以下问题:C# Range类的具体用法?C# Range怎么用?C# Range使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Range类属于Microsoft.Office.Interop.Excel命名空间,在下文中一共展示了Range类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: openXL
public static void openXL(string xlp)
{
xla = new Excel.Application();
xlw = xla.Workbooks.Open(xlp);
xls = xlw.Worksheets.get_Item(1);
xlr = xls.UsedRange;
}
开发者ID:gluefish,项目名称:WatiX-cs-U,代码行数:7,代码来源:ExcelUtils.cs
示例2: readExcel
public void readExcel()
{
string valueString = string.Empty;
objExcelApp = new Microsoft.Office.Interop.Excel.Application();
objBooks = (Excel.Workbooks)objExcelApp.Workbooks;
//Open the workbook containing the address data.
objBook = objBooks.Open(@"C:\Temp\data\Test.xlsx", Missing.Value, Missing.Value,
Missing.Value, Missing.Value,
Missing.Value, Missing.Value,
Missing.Value, Missing.Value,
Missing.Value, Missing.Value,
Missing.Value, Missing.Value,
Missing.Value, Missing.Value);
//Get a reference to the first sheet of the workbook.
objSheets = objBook.Worksheets;
objSheet = (Excel._Worksheet)objSheets.get_Item(1);
//Select the range of data containing the addresses and get the outer boundaries.
rngLast = objSheet.get_Range("A1").SpecialCells(Microsoft.Office.Interop.Excel.XlCellType.xlCellTypeLastCell);
long lLastRow = rngLast.Row;
long lLastCol = rngLast.Column;
// Iterate through the data and concatenate the values into a comma-delimited string.
for (long rowCounter = 1; rowCounter <= lLastRow; rowCounter++)
{
for (long colCounter = 1; colCounter <= lLastCol; colCounter++)
{
//Write the next value into the string.
Excel.Range cell = (Excel.Range)objSheet.Cells[rowCounter, colCounter];
string cellvalue = cell.Value.ToString();
//TODO: add your business logic for retrieve cell value
}
}
}
开发者ID:anthonied,项目名称:CRM,代码行数:34,代码来源:ReadExcel.cs
示例3: StudentWorkbook
/// <summary>
/// Class constructor does all the work
/// </summary>
/// <param name="excelApp"></param>
/// <param name="fileName"></param>
public StudentWorkbook( Excel.Application excelApp, string fileName )
{
try // to open the student's spreadsheet
{
excelWorkbook = excelApp.Workbooks.Open( fileName, 0,
true, 5, "", "", false, Excel.XlPlatform.xlWindows, "", true, // read only
false, 0, true, false, false );
}
catch ( Exception e )
{
Console.WriteLine( "error: " + e.Message );
Console.WriteLine( "Could not open spreadsheet " + fileName );
}
Excel.Sheets excelSheets = excelWorkbook.Worksheets; // get the Worksheets collection
Excel.Worksheet excelWorksheet = excelSheets[ 1 ]; // get the first one
// get the Team Number cell
Excel.Range excelCell = (Excel.Range)excelWorksheet.get_Range( "B4", "B4" );
// try to convert this cell to an integer
if ( ( teamNumber = TryForInt( excelCell.Value ) ) == 0 )
{
Console.WriteLine( "\nTeam number invalid in " + fileName + "\n" );
}
// get the scores cells
scores = excelWorksheet.get_Range( "B7", "B15" );
// get the Additional Comments cell
comments = excelWorksheet.get_Range( "B18", "B18" );
} // end of StudentWorkbook()
开发者ID:cyboss77,项目名称:ClassAssessments,代码行数:38,代码来源:StudentWorkbook.cs
示例4: Insert
public Insert(Excel.Application application, CultureInfo culture)
{
try {
_excelapp = application;
_culture = culture;
_range = application.ActiveWindow.RangeSelection;
} catch (Exception ex) { new FrmException(_excelapp, ex).ShowDialog(); }
}
开发者ID:alnemer,项目名称:excel-qa-tools,代码行数:8,代码来源:Insert.cs
示例5: addData
public void addData(int row, int col, string data,
string cell1, string cell2, string format)
{
worksheet.Cells[row, col] = data;
workSheet_range = worksheet.get_Range(cell1, cell2);
workSheet_range.Borders.Color = System.Drawing.Color.Black.ToArgb();
workSheet_range.NumberFormat = format;
}
开发者ID:hoangtung56pm,项目名称:KPINew,代码行数:8,代码来源:CreateExcelDoc.cs
示例6: Date
public Date(Excel.Application application, CultureInfo culture)
{
try {
_excelapp = application;
_culture = culture;
_range = application.ActiveWindow.RangeSelection;
_minDateTime = new DateTime(1900, 1, 1);
} catch (Exception ex) { new FrmException(_excelapp, ex).ShowDialog(); }
}
开发者ID:alnemer,项目名称:excel-qa-tools,代码行数:9,代码来源:Date.cs
示例7: Gen
public Gen(Excel.Application application, CultureInfo culture)
{
try {
_excelapp = application;
_culture = culture;
_range = application.ActiveWindow.RangeSelection;
_singlesel = _range.Columns.Count == 1 && _range.Rows.Count == 1;
_fnb = _singlesel ? new FieldNumber("Number of rows", "", 100, 1, true) : null;
} catch (Exception ex) { new FrmException(_excelapp, ex).ShowDialog(); }
}
开发者ID:alnemer,项目名称:excel-qa-tools,代码行数:10,代码来源:Gen.cs
示例8: NormalDistribution
//Constructor that takes an Excel range as an argument
//The data is stored in the cells of the range
public NormalDistribution(Excel.Range r)
{
_cells = r;
_size = r.Count;
_mean = __mean();
_variance = __variance();
_standard_deviation = __standard_deviation();
_error = __error();
_ranked_errors = __rank_errors();
}
开发者ID:plasma-umass,项目名称:DataDebug,代码行数:12,代码来源:NormalDistribution.cs
示例9: generatExcelNoSubmit
public void generatExcelNoSubmit(string f)
{
string file_Name = f;
m_oExcelApp = new Excel.Application();
m_oExcelApp.Visible = false;
m_oExcelApp.UserControl = false;
m_oSheet = null;
excelRange = null;
try
{
m_oBook = m_oExcelApp.Workbooks.Add(missing);
Excel.Sheets sheets = m_oBook.Worksheets;
//Add new 4 Sheet
//sheets.Add(System.Type.Missing, m_oBook.Sheets[3], 1, Excel.XlSheetType.xlWorksheet);
//Product Sheet [Sheet1]
m_oSheet = (Excel._Worksheet)m_oBook.Sheets[1];
m_oSheet.Activate();
m_oSheet.Name = "รายการเสนอซื้อ";
SetData_to_SheetNoSubmit();
string template = Application.StartupPath;
string strRunReport = file_Name;
//string strPass = "ktc123"; password
m_oBook.SaveAs(strRunReport, Excel.XlFileFormat.xlWorkbookNormal, null, null, null, null, Excel.XlSaveAsAccessMode.xlShared, null, null, null, null, null);
m_oExcelApp.Visible = true;
}
catch (interop.COMException ex)
{
MessageBox.Show("Error accessing Excel: " + ex.ToString());
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.ToString());
}
finally
{
if (m_oExcelApp == null)
{
m_oExcelApp.Quit();
m_oExcelApp = null;
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
GC.WaitForPendingFinalizers();
}
}
}
开发者ID:itktc,项目名称:projectktc-v2,代码行数:55,代码来源:frmMainPo.cs
示例10: Sheet1_Startup
private void Sheet1_Startup(object sender, System.EventArgs e)
{
rngUp = this.Range["B2", missing];
rngDown = this.Range["B3", missing];
rngInterest = this.Range["B4", missing];
rngInitial = this.Range["B5", missing];
rngPeriods = this.Range["B6", missing];
rngExercise = this.Range["B7", missing];
rngRuns = this.Range["B8", missing];
rngRemote = this.Range["B9", missing];
}
开发者ID:Farouq,项目名称:semclone,代码行数:11,代码来源:Sheet1.cs
示例11: ReportBuilder
public ReportBuilder()
{
app = new Excel.Application();
appBooks = app.Workbooks;
currentBook = appBooks.Add(Missing.Value);
sheets = currentBook.Worksheets;
currentSheet = (Excel._Worksheet)sheets.get_Item(1);
range = currentSheet.get_Range("A1", Missing.Value);
charts = currentSheet.ChartObjects(Type.Missing);
chartObject = charts.Add(400, LastIndex, chartWidth, chartHeight);
}
开发者ID:FarrelLabs,项目名称:lab1,代码行数:11,代码来源:ReportBuilder.cs
示例12: ReplaceExcelRange
public static void ReplaceExcelRange(Range com, InputSample input)
{
bool done = false;
while (!done)
{
try
{
com.Value2 = input.GetInputArray();
done = true;
}
catch (Exception)
{
}
}
}
开发者ID:plasma-umass,项目名称:DataDebug,代码行数:16,代码来源:BootMemo.cs
示例13: addData
public void addData(int row, int col, string content, bool bold, bool italic, bool underline, int? size, string fontName)
{
//Data
worksheet.Cells[row, col] = content;
//Cell format
workSheet_range = worksheet.get_Range(string.Empty + new string((char)(col + 64), 1) + row.ToString());
workSheet_range.Borders.Color = System.Drawing.Color.Black.ToArgb();
workSheet_range.Font.Bold = bold;
workSheet_range.Font.Italic = italic;
workSheet_range.Font.Underline = underline;
if (size != null)
workSheet_range.Font.Size = size;
if(fontName != null)
workSheet_range.Font.Name = fontName;
}
开发者ID:Celtc,项目名称:Barcode-Reader---Exporter,代码行数:16,代码来源:ExcelAPI.cs
示例14: ReadExcel
public static Excel1.Range ReadExcel(string filePath, int workSheetNumber)
{
try
{
string startupPath = System.IO.Directory.GetCurrentDirectory();
string outPutDirectory = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase);
string xmlfilepath = Path.Combine(outPutDirectory + filePath);
string xmlfile_path = new Uri(xmlfilepath).LocalPath;
xlApp = new Excel1.Application();
xlWorkBook = xlApp.Workbooks.Open(xmlfile_path, 0, false, 5, "", "", true, Excel1.XlPlatform.xlWindows, "\t", true, false, 0, true, true, false);
xlWorkSheet = (Excel1.Worksheet)xlWorkBook.Worksheets.get_Item(workSheetNumber);
return range = xlWorkSheet.UsedRange;
}
catch (Exception)
{
return null;
}
}
开发者ID:kirankumarb4u,项目名称:SeeTestAutomation,代码行数:18,代码来源:ReadContentMethods.cs
示例15: createHeaders
public void createHeaders(int row, int col, string htext, string cell1,
string cell2, int mergeColumns, string b, bool font, int size, string
fcolor)
{
worksheet.Cells[row, col] = htext;
workSheet_range = worksheet.get_Range(cell1, cell2);
//workSheet_range.Merge(mergeColumns);
switch (b)
{
case "YELLOW":
workSheet_range.Interior.Color = System.Drawing.Color.Gray.ToArgb();
break;
case "GRAY":
workSheet_range.Interior.Color = System.Drawing.Color.Gray.ToArgb();
break;
case "GAINSBORO":
workSheet_range.Interior.Color =
System.Drawing.Color.Gainsboro.ToArgb();
break;
case "Turquoise":
workSheet_range.Interior.Color =
System.Drawing.Color.Turquoise.ToArgb();
break;
case "PeachPuff":
workSheet_range.Interior.Color =
System.Drawing.Color.PeachPuff.ToArgb();
break;
default:
// workSheet_range.Interior.Color = System.Drawing.Color..ToArgb();
break;
}
workSheet_range.Borders.Color = System.Drawing.Color.Black.ToArgb();
workSheet_range.Font.Bold = font;
workSheet_range.ColumnWidth = size;
if (fcolor.Equals(""))
{
workSheet_range.Font.Color = System.Drawing.Color.White.ToArgb();
}
else
{
workSheet_range.Font.Color = System.Drawing.Color.Red;
}
}
开发者ID:hoangtung56pm,项目名称:KPINew,代码行数:44,代码来源:CreateExcelDoc.cs
示例16: SpreadsheetSplitter
public SpreadsheetSplitter(string filename, string destination_folder)
{
excel = new Excel.Application();
excel.Visible = false;
excel.DisplayAlerts = false;
workbook = excel.Workbooks.Open(filename, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
first_sheet = (Excel.Worksheet)workbook.Sheets.get_Item(1);
string main_sheet_name = first_sheet.Name;
output_folder = destination_folder;
sheet_range = first_sheet.UsedRange;
heading_column_start = 1;
heading_column_end = sheet_range.Columns.Count - 1;
heading_row_start = 1;
heading_row_end = 2;
start_row = 3;
start_col = GetExcelColumnName(heading_column_start);
end_col = GetExcelColumnName(heading_column_end);
}
开发者ID:HannesBenson,项目名称:Data-Splitter,代码行数:19,代码来源:SpreadsheetSplitter.cs
示例17: OpenExcelDoc
public void OpenExcelDoc(String ofd)
{
Thread.Sleep(1000);
application = new MExcel.Application();
try
{
workBook = application.Workbooks.Open(ofd);
}
catch (System.Runtime.InteropServices.COMException)
{
MessageBox.Show("Не удалось открыть файл Excel","Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Information);
application.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(application);
System.GC.Collect();
application = new MExcel.Application();
workBook = application.Workbooks.Open(ofd);
}
workSheet = (MExcel.Worksheet)workBook.Worksheets.get_Item(4);
range = workSheet.UsedRange;
}
开发者ID:PAlAl,项目名称:ImportMStoDB,代码行数:20,代码来源:Verificator.cs
示例18: ExcelApplication
/// <summary>
/// Конструктор для инициалицазии переменных класса
/// </summary>
/// <param name="fileExcel">Путь к файлу для открытия</param>
public ExcelApplication(string fileExcel)
: base(fileExcel)
{
try
{
excelApp = new Excel.Application();
excelBook = excelApp.Workbooks.Open(fileToExcel);
excelSheet = (Excel.Worksheet)excelBook.Worksheets.get_Item(1);
excelRange = excelSheet.UsedRange;
}
catch
{
MessageBox.Show("Заданный файл Excel не доступен!");
//excelBook.Close(falseObj,missingObj,missingObj);
excelApp.Quit();
excelBook = null;
excelApp = null;
Application.Exit();
}
}
开发者ID:Homecoming07,项目名称:Word-Excel,代码行数:24,代码来源:ExcelApplication.cs
示例19: CXLRTemplateDef
//constructor
public CXLRTemplateDef(Excel.Range dsRange){
for(int i = 1; i <= dsRange.Rows.Count; i++) {
Excel.Range vCurRow = (Excel.Range)dsRange.Rows[i, Type.Missing];
String vCurDefValue = ExcelSrv.ExtractCellValue(vCurRow.Cells[1, 1]);
if (!String.IsNullOrEmpty(vCurDefValue) && vCurDefValue.StartsWith(csGrpHeaderDef)) {
String vFldName = ExcelSrv.ExtractFieldName(vCurDefValue);
this._headerFormats.Add(vFldName, vCurRow);
} else
if(!String.IsNullOrEmpty(vCurDefValue) && vCurDefValue.StartsWith(csGrpFooterDef)) {
String vFldName = ExcelSrv.ExtractFieldName(vCurDefValue);
this._footerFormats.Add(vFldName, vCurRow);
} else
if(!String.IsNullOrEmpty(vCurDefValue) && (vCurDefValue.Equals(csDetailsDef))) {
this._detailsRng = vCurRow;
} else
if(!String.IsNullOrEmpty(vCurDefValue) && (vCurDefValue.Equals(csTotalsDef))) {
this._totalsRng = vCurRow;
}
}
}
开发者ID:tormoz70,项目名称:Bio.Framework.8,代码行数:21,代码来源:CXLRTemplateDef.cs
示例20: OpenExcelDoc
/// <summary>
/// Открыть файл - адрес берется из характеристики
/// </summary>
public void OpenExcelDoc(/*String ofd*/)
{
Thread.Sleep(1000);
application = new MExcel.Application();
try
{
workBook = application.Workbooks.Open(characteristic.FileAdres);
}
catch (System.Runtime.InteropServices.COMException error)
{
//MessageBox.Show(error.Message, "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Information);
application.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(application);
System.GC.Collect();
application = new MExcel.Application();
workBook = application.Workbooks.Open(characteristic.FileAdres);
}
workSheet = (MExcel.Worksheet)workBook.Worksheets.get_Item(characteristic.NumberList);
range = workSheet.UsedRange;
}
开发者ID:PAlAl,项目名称:ImportMStoDB,代码行数:23,代码来源:OrderingProcessor.cs
注:本文中的Microsoft.Office.Interop.Excel.Range类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论