Click here to Skip to main content
15,900,325 members
Home / Discussions / C#
   

C#

 
QuestionDateTime format Problem Pin
sks838-Mar-07 2:52
sks838-Mar-07 2:52 
AnswerRe: DateTime format Problem Pin
Colin Angus Mackay8-Mar-07 3:21
Colin Angus Mackay8-Mar-07 3:21 
Questionflash animations on forms [modified] Pin
nadapublicidad8-Mar-07 2:29
nadapublicidad8-Mar-07 2:29 
AnswerRe: flash animations on forms Pin
VirtualVoid.NET8-Mar-07 2:36
VirtualVoid.NET8-Mar-07 2:36 
AnswerRe: flash animations on forms Pin
Russell Jones8-Mar-07 4:19
Russell Jones8-Mar-07 4:19 
QuestionExcel Read/Write Pin
dotnethunk8-Mar-07 2:21
dotnethunk8-Mar-07 2:21 
AnswerRe: Excel Read/Write Pin
N a v a n e e t h8-Mar-07 2:23
N a v a n e e t h8-Mar-07 2:23 
GeneralRe: Excel Read/Write Pin
dotnethunk8-Mar-07 2:39
dotnethunk8-Mar-07 2:39 
hi Navneeth
Thanks for ur concern ,
here is my code
initailizing code:
Microsoft.Office.Interop.Excel.Application objExcel = new Microsoft.Office.Interop.Excel.Application();

code for Reading from excel:-
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
Workbook CallListWorkBook = objExcel.Workbooks.Open(openFileDialog1.FileName, 0, true, 5, "", "", true, XlPlatform.xlWindows, "\t", false, false, 0, true, 0, 0);
Sheets CallingSheet = CallListWorkBook.Worksheets;
Worksheet worksheet = (Worksheet)CallingSheet.get_Item(1);
Range CallingRange = worksheet.get_Range("A1", "A1");
CallingRange = CallingRange.get_End(XlDirection.xlToRight);
totalColumn = CallingRange.Column;
string downAddress = CallingRange.get_End(XlDirection.xlDown).get_Address(false, false, XlReferenceStyle.xlA1, Type.Missing, Type.Missing);
//string downAddress = CallingRange.get_Address(false, false, XlReferenceStyle.xlA1, Type.Missing, Type.Missing);
CallingRange = worksheet.get_Range("A1", downAddress);
System.Array CallingValues = (System.Array)CallingRange.Cells.Value2;
//objExcel.Workbooks.Close();
//objExcel.Quit();
ConvertToStringArray(CallingValues);
}

Code for writing in excel:

Excel.Workbooks CallListWorkBooks;
Excel.Sheets CallingSheet;
Excel._Worksheet worksheet;
Excel.Range CallingRange;
Excel.Workbook CallListWorkBook;
try
{

// Instantiate Excel and start a new workbook.
// objExcel = new Excel.Application();
CallListWorkBooks = objExcel.Workbooks;
CallListWorkBook = CallListWorkBooks.Add(Missing.Value);
CallingSheet = CallListWorkBook.Worksheets;
worksheet = (Excel._Worksheet)CallingSheet.get_Item(1);
//Get the CallingRange where the starting cell has the address
//m_sStartingCell and its dimensions are m_iNumRows x m_iNumCols.
CallingRange = worksheet.get_Range("A1", Missing.Value);
int totalrows = arr.Count;
CallingRange = CallingRange.get_Resize(totalrows, 1);
//Create an array.
string[,] saRet = new string[totalrows, 1];
//Fill the array.
int j = 0;
for (long iRow = 0; iRow < totalrows; iRow++)
{
for (long iCol = 0; iCol < 1; iCol++)
{
//Put a counter in the cell.
saRet[iRow, iCol] = Convert.ToString(arr[j]);
//saRet[iRow, iCol] = Convert.ToDouble(theArray[i, 2]);
j++;
}
}

//Set the CallingRange value to the array.
CallingRange.set_Value(Missing.Value, saRet);

if (IsActive == 1)
{
CallListWorkBook.SaveAs("c:\\Active.xls", Excel.XlFileFormat.xlWorkbookNormal, null, null, false, false, Excel.XlSaveAsAccessMode.xlShared, false, false, null, null, null);

}
else
{

CallListWorkBook.SaveAs("c:\\inactive.xls", Excel.XlFileFormat.xlWorkbookNormal, null, null, false, false, Excel.XlSaveAsAccessMode.xlShared, false, false, null, null, null);

}
objExcelForWriting.Visible = false;
objExcelForWriting.UserControl = false;
CallListWorkBooks.Close();
objExcel.Quit();
}

catch (Exception theException)
{
String errorMessage;
errorMessage = "Error: ";
errorMessage = String.Concat(errorMessage, theException.Message);
errorMessage = String.Concat(errorMessage, " Line: ");
errorMessage = String.Concat(errorMessage, theException.Source);
MessageBox.Show(errorMessage);
}

}

QuestionC# interfaces doesn't contain data members Pin
DGtech8-Mar-07 2:17
DGtech8-Mar-07 2:17 
AnswerRe: C# interfaces doesn't contain data members Pin
Pete O'Hanlon8-Mar-07 2:22
mvePete O'Hanlon8-Mar-07 2:22 
AnswerRe: C# interfaces doesn't contain data members Pin
Colin Angus Mackay8-Mar-07 2:22
Colin Angus Mackay8-Mar-07 2:22 
QuestionUrgent: Vista elevating Users Pin
Lucian.Palcu8-Mar-07 0:19
Lucian.Palcu8-Mar-07 0:19 
AnswerRe: Urgent: Vista elevating Users Pin
Pete O'Hanlon8-Mar-07 0:25
mvePete O'Hanlon8-Mar-07 0:25 
AnswerRe: Urgent: Vista elevating Users Pin
Colin Angus Mackay8-Mar-07 2:04
Colin Angus Mackay8-Mar-07 2:04 
Questionplz help me!!!!!!!!!!!!! Pin
Member 38888727-Mar-07 23:59
Member 38888727-Mar-07 23:59 
AnswerRe: plz help me!!!!!!!!!!!!! Pin
Edmundisme8-Mar-07 5:13
Edmundisme8-Mar-07 5:13 
Questiongac Pin
groundzero1117-Mar-07 23:39
groundzero1117-Mar-07 23:39 
AnswerRe: gac Pin
Pete O'Hanlon8-Mar-07 1:25
mvePete O'Hanlon8-Mar-07 1:25 
AnswerRe: gac Pin
N a v a n e e t h8-Mar-07 2:26
N a v a n e e t h8-Mar-07 2:26 
QuestionHow to determine the size of my class Pin
Arindam Tewary7-Mar-07 23:26
professionalArindam Tewary7-Mar-07 23:26 
AnswerRe: How to determine the size of my class Pin
Pete O'Hanlon8-Mar-07 0:22
mvePete O'Hanlon8-Mar-07 0:22 
QuestionOpen and Write in Console window Pin
harvid7-Mar-07 23:24
harvid7-Mar-07 23:24 
AnswerRe: Open and Write in Console window Pin
rah_sin7-Mar-07 23:53
professionalrah_sin7-Mar-07 23:53 
GeneralRe: Open and Write in Console window [modified] Pin
harvid8-Mar-07 0:10
harvid8-Mar-07 0:10 
GeneralRe: Open and Write in Console window Pin
\laddie8-Mar-07 23:57
\laddie8-Mar-07 23:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.