Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void exportBtn_Click(object sender, EventArgs e)
- {
- OleDbCommand newRow = new OleDbCommand();
- newRow.CommandType = CommandType.Text;
- newRow.CommandText = "INSERT INTO [Sheet1$] ([Company:], [County:], [State:], [Notes:], [User:], [Email:], [Username:], [Password:], [SMMM PWD:], [CAD:]) VALUES (1,2,3,4,5,6,7,8,9,10)";
- newRow.Connection = connectionExl;
- connectionExl.Open();
- newRow.ExecuteNonQuery();
- connectionExl.Close();
- }
- public int getLastRow(Excel.Worksheet ws)
- {
- object[,] arData = ws.UsedRange.FormulaR1C1; // FormulaR1C1 returns only string in 2 dimensional array
- for (int iRow = arData.GetUpperBound(0); iRow > 0; iRow--) {
- for (int iCol = 1; iCol <= arData.GetUpperBound(1); iCol++) {
- if (arData[iRow, iCol].ToString() != "") { return iRow; }
- }
- }
- return 0;
- }
- int lastRow = ws.Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell).Row;
- using System.Runtime.InteropServices;
- using Excel = Microsoft.Office.Interop.Excel;
- void test()
- {
- Excel.Application xlApp = csXL.StartExcel();
- Excel.Worksheet ws = xlApp.ActiveSheet;
- int irow = getLastRow(ws);
- }
- public static Excel.Application StartExcel()
- {
- Excel.Application instance = null;
- try { instance = (Excel.Application)Marshal.GetActiveObject("Excel.Application"); }
- catch (System.Runtime.InteropServices.COMException ex) { instance = new Excel.Application(); }
- return instance;
- }
- object[,] arLoad = new object[0, 9]; arLoad[0, 0] = 1; arLoad[0, 1] = 2;
- ws.Range["A" + irow + ":J" + irow].FormulaR1C1 = arLoad; // or use Value instead of FormulaR1C1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement