H
hanlei
I can write data into excel without password:
objBook = objBooks.Add("D:\\1.xls");
objSheets = objBook.Worksheets;
objSheet = (Excel._Worksheet)objSheets.get_Item(1);
//Get the range where the starting cell has the address
//m_sStartingCell and its dimensions are m_iNumRows x m_iNumCols.
range = objSheet.get_Range("G1", Missing.Value);
range = range.get_Resize(1,1);
if (this.FillWithStrings.Checked == false)
{
//Create an array.
double[,] saRet = new double[1,1];
//Fill the array.for (long iRow = 0; iRow < 1; iRow++)
{
{
for (long iCol = 0; iCol < 1; iCol++)//Put a counter in the cell.
saRet[iRow, iCol] = iRow * iCol;
}
}
//Set the range value to the array.
range.set_Value(Missing.Value, saRet );
}
objApp.Visible = false;
objApp.UserControl = true;
// Save the workbook and quit Excel.
objBook.SaveAs("D:\\1.xls", m_objOpt, m_objOpt,
m_objOpt, m_objOpt, m_objOpt, Excel.XlSaveAsAccessMode.xlNoChange,
m_objOpt, m_objOpt, m_objOpt, m_objOpt, m_objOpt);
objBook.Close(false, m_objOpt, m_objOpt);
objApp.Quit();
but if the excel have password,I cant do.
thanks!
objBook = objBooks.Add("D:\\1.xls");
objSheets = objBook.Worksheets;
objSheet = (Excel._Worksheet)objSheets.get_Item(1);
//Get the range where the starting cell has the address
//m_sStartingCell and its dimensions are m_iNumRows x m_iNumCols.
range = objSheet.get_Range("G1", Missing.Value);
range = range.get_Resize(1,1);
if (this.FillWithStrings.Checked == false)
{
//Create an array.
double[,] saRet = new double[1,1];
//Fill the array.for (long iRow = 0; iRow < 1; iRow++)
{
{
for (long iCol = 0; iCol < 1; iCol++)//Put a counter in the cell.
saRet[iRow, iCol] = iRow * iCol;
}
}
//Set the range value to the array.
range.set_Value(Missing.Value, saRet );
}
objApp.Visible = false;
objApp.UserControl = true;
// Save the workbook and quit Excel.
objBook.SaveAs("D:\\1.xls", m_objOpt, m_objOpt,
m_objOpt, m_objOpt, m_objOpt, Excel.XlSaveAsAccessMode.xlNoChange,
m_objOpt, m_objOpt, m_objOpt, m_objOpt, m_objOpt);
objBook.Close(false, m_objOpt, m_objOpt);
objApp.Quit();
but if the excel have password,I cant do.
thanks!