Click here to Skip to main content
15,888,461 members
Home / Discussions / C#
   

C#

 
QuestionHow do I generate reports dynamically Pin
rehpot3-Aug-09 6:05
rehpot3-Aug-09 6:05 
QuestionFor Loop Pattern Pin
gamer11273-Aug-09 5:26
gamer11273-Aug-09 5:26 
AnswerRe: For Loop Pattern Pin
PIEBALDconsult3-Aug-09 5:45
mvePIEBALDconsult3-Aug-09 5:45 
GeneralRe: For Loop Pattern Pin
gamer11273-Aug-09 6:06
gamer11273-Aug-09 6:06 
GeneralRe: For Loop Pattern Pin
riced3-Aug-09 6:33
riced3-Aug-09 6:33 
GeneralRe: For Loop Pattern Pin
Pete O'Hanlon3-Aug-09 22:03
mvePete O'Hanlon3-Aug-09 22:03 
AnswerRe: For Loop Pattern Pin
molesworth3-Aug-09 10:12
molesworth3-Aug-09 10:12 
Questionhow to write in excel cells using DataReader if a particular cell is “ReadOnly” using C# Pin
Krishna Aditya3-Aug-09 4:16
Krishna Aditya3-Aug-09 4:16 
Hi,

I am importing data to Excel sheets from Database. For this, I am using datareader. The excel sheet template has some macros and few formulae calculated and its not the normal excel worksheet. so I have to write the data into the excel sheet only if the particular cell is allowed to write. If not, the data shouldn't be imported.



so, for this, I have a XML file which says from which column i should start writing and which row it should stop, I have done for many sheets. But in one sheet, I have first cell of the row is "readonly" and the rest are write access permitted.

As, I get entire row from DB using Datareader, I am stuck up to write to other cells, except for the particular cell.  



I am attaching the code snippet for   reference. \

Please help me in doing this.

Sample ::

                                                                        if (reader.HasRows)
                                                                                          {
                                                                                                   minRow = 0;
                                                                                                   minCol = 0;
                                                                                                   Excel.Workbook SelWorkBook = excelAppln.Workbooks.Open(curfile, 0, false, 5, "", "", false, Excel.XlPlatform.xlWindows, "", true, false, 0, false, false, false);
                                                                                                   Excel.Sheets excelSheets = SelWorkBook.Worksheets;
Excel.Worksheet excelworksheet = (Excel.Worksheet)excelSheets.get_Item(CurSheetName);

                                                                                                   // Process each result in the result set
                                                                                                   while (reader.Read())
                                                                                                   {
                                                                                                            // Create an array big enough to hold the column values
                                                                                                            object[] values = new object[reader.FieldCount];

                                                                                                            // Add the array to the ArrayList
                                                                                                            rowList.Add(values);

                                                                                                            // Get the column values into the array
                                                                                                            reader.GetValues(values);

                                                                                                            int iValueIndex = 0;

                                                                                                            // If the Reading Format is by ColumnByColumn
                                                                                                            if (CurTaskNode.ReadFormat == "ColumnbyColumn")
                                                                                                            {
                                                                                                                     minCol = 0;
                                                                                                                     //   minRow = 0;
                                                                                                                     for (int iCol = 0; iCol < CurTaskNode.HeaderData.Length; iCol++)
                                                                                                                     {

                                                                                                                              // Checking whether the Header data exists or not
                                                                                                                              if (CurTaskNode.HeaderData[minCol] != "")
                                                                                                                              {
                                                                                                                                       // Assigning the Value from reader to the particular cell in excel sheet
                                                                                                                                       excelworksheet.Cells[CurTaskNode.DATA_MIN_ROW + minRow, CurTaskNode.DATA_MIN_COL + minCol] = values[iValueIndex];
                                                                                                                                       iValueIndex++;

                                                                                                                              }
                                                                                                                              minCol++;
                                                                                                                     }
                                                                                                                     minRow++;
                                                                                                            }
} SelWorkBook.Close(true, curfile, null);


This piece of code reads the data from DB if the reader has rows.It then opens a new preloaded excel template file and assigns the reader data to the Values object. Then for the header length (HeaderData.Length) in XML file it writes to the each excel cell and finally it saves the file and closes. The location where the data is written is excelworksheet.Cells[CurTaskNode.DATA_MIN_ROW + minRow, CurTaskNode.DATA_MIN_COL + minCol] = values[iValueIndex]; // Actually a check needs to be performed b4 this whether to write into cell. i'm not able to do it.
Please help me in resolving this.



Thank You,

Ramm
Questionproblem with windows appln Pin
Member 30578873-Aug-09 1:15
Member 30578873-Aug-09 1:15 
AnswerRe: problem with windows appln Pin
Michael Bookatz3-Aug-09 1:36
Michael Bookatz3-Aug-09 1:36 
GeneralRe: problem with windows appln Pin
Member 30578873-Aug-09 2:00
Member 30578873-Aug-09 2:00 
GeneralRe: problem with windows appln Pin
Baeltazor3-Aug-09 15:47
Baeltazor3-Aug-09 15:47 
AnswerRe: problem with windows appln Pin
Not Active3-Aug-09 2:17
mentorNot Active3-Aug-09 2:17 
GeneralRe: problem with windows appln Pin
Member 30578873-Aug-09 2:47
Member 30578873-Aug-09 2:47 
GeneralRe: problem with windows appln Pin
Mycroft Holmes3-Aug-09 3:32
professionalMycroft Holmes3-Aug-09 3:32 
GeneralRe: problem with windows appln Pin
Not Active3-Aug-09 5:00
mentorNot Active3-Aug-09 5:00 
AnswerRe: problem with windows appln Pin
Mike Ellison3-Aug-09 3:17
Mike Ellison3-Aug-09 3:17 
GeneralRe: problem with windows appln Pin
Member 305788718-Aug-09 23:54
Member 305788718-Aug-09 23:54 
GeneralRe: problem with windows appln Pin
for120619-Aug-09 18:27
for120619-Aug-09 18:27 
GeneralRe: problem with windows appln Pin
Member 305788719-Aug-09 19:00
Member 305788719-Aug-09 19:00 
QuestionNeed to store value common Pin
Ramkumar_S3-Aug-09 1:11
Ramkumar_S3-Aug-09 1:11 
AnswerRe: Need to store value common Pin
musefan3-Aug-09 2:23
musefan3-Aug-09 2:23 
GeneralRe: Need to store value common Pin
Ramkumar_S3-Aug-09 4:10
Ramkumar_S3-Aug-09 4:10 
QuestionBHO SetSite is not called? Pin
svt gdwl3-Aug-09 1:04
svt gdwl3-Aug-09 1:04 
QuestionCustom Installer Class Pin
Prakash N3-Aug-09 0:48
Prakash N3-Aug-09 0:48 

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.