Znači ako imamo sCellValue = "Dobar dan" , ta vrijednost se upisuje u A2. I to sve super radi, ali riješenje kao što sam već rekao nije generično. Razlog je taj što ja imam u konstruktoru jedan
object [ ] oColumns = new object [ ] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N" };
iz kojeg uzimam imena celija sto naravno nije ok. Meni sad treba nekekav property, method, bilo sta da se izbjegne ovaj način pretrage celija. Ja nisam uspio da pronađem nista sto bi mi ovo moglo rijesiti.
Dio funkcije je ispod
Code:
public void FormatingCells ( Excel.Workbook oWorkbook, string sCellName, string sCellValue )
{
Excel.Worksheet oWorkSheet = oWorkbook.ActiveSheet as Excel.Worksheet;
int iNumberofColumns = oWorkSheet.Cells.Find ( "*", Type.Missing, Excel.XlFindLookIn.xlValues, Excel.XlLookAt.xlWhole,
Excel.XlSearchOrder.xlByColumns, Excel.XlSearchDirection.xlPrevious,
false, false, Type.Missing ).Column;
int iNumberofRows = oWorkSheet.Cells.Find ( "*", Type.Missing, Excel.XlFindLookIn.xlValues, Excel.XlLookAt.xlWhole,
Excel.XlSearchOrder.xlByRows, Excel.XlSearchDirection.xlPrevious,
false, false, Type.Missing ).Row;
for ( int i = 1; i <= iNumberofRows; i++ )
{
for ( int j = 0; j < iNumberofColumns; j++ )
{
string s = oColumns.GetValue ( j ).ToString ( ); // gdje je oColumn string [] sa { vrijednostima {A, B,...N};
string sCurrentCell = s + i.ToString ( );
string sNameCells = "";
sNameCells = oWorkSheet.Range [sCurrentCell.ToString ( )].Value2 as string;
if ( sNameCells != null && sNameCells == sCellName )
{
oWorkSheet.Cells [i + 1, s] = sCellValue;
sNameCells = null;
break;
}
}
}
oRange = oWorkSheet.get_Range ( "A2", "I40" );
oRange.EntireColumn.AutoFit ( )
public void FormatingCells ( Excel.Workbook oWorkbook, string sCellName, string sCellValue )
{
Excel.Worksheet oWorkSheet = oWorkbook.ActiveSheet as Excel.Worksheet;
int iNumberofColumns = oWorkSheet.Cells.Find ( "*", Type.Missing, Excel.XlFindLookIn.xlValues, Excel.XlLookAt.xlWhole,
Excel.XlSearchOrder.xlByColumns, Excel.XlSearchDirection.xlPrevious,
false, false, Type.Missing ).Column;
int iNumberofRows = oWorkSheet.Cells.Find ( "*", Type.Missing, Excel.XlFindLookIn.xlValues, Excel.XlLookAt.xlWhole,
Excel.XlSearchOrder.xlByRows, Excel.XlSearchDirection.xlPrevious,
false, false, Type.Missing ).Row;
for ( int i = 1; i <= iNumberofRows; i++ )
{
for ( int j = 0; j < iNumberofColumns; j++ )
{
string s = oColumns.GetValue ( j ).ToString ( ); // gdje je oColumn string [] sa { vrijednostima {A, B,...N};
string sCurrentCell = s + i.ToString ( );
string sNameCells = "";
sNameCells = oWorkSheet.Range [sCurrentCell.ToString ( )].Value2 as string;
if ( sNameCells != null && sNameCells == sCellName )
{
oWorkSheet.Cells [i + 1, s] = sCellValue;
sNameCells = null;
break;
}
}
}
oRange = oWorkSheet.get_Range ( "A2", "I40" );
oRange.EntireColumn.AutoFit ( )