locked
Excel output RRS feed

  • Question

  • User-1225802336 posted

    Hi i have the following code which outputs data from my database onto an excel spread sheet, the problem is the data is going across, what i want to do is make it go into specific cells, for instance the question in Cell A and the answer in Cell B. How do i do this?

     

        public void DownloaQuestionnaireCSV(HttpResponse httpResponse, int intQuestionnaireID)
        {
          string strOutputHeader = "";
          string strOutput = "";
    
          strOutputHeader += "\"Questionnaire Name\",";
          strOutputHeader += "\"QuestionnaireDescription\",";
    
          strOutputHeader += "\"IntroText\",";
          strOutputHeader += "\"InstructionText\",";
    
          strOutputHeader += "\"Strapline\",";
          strOutputHeader += "\"Authors\",";
    
          strOutputHeader += "\"Add Date\",";
          strOutputHeader += "\"Edit Date\",";
    
    
          strOutputHeader += "\"Questions\",";
          strOutputHeader += "\"Answers\",";
    
    
          httpResponse.AddHeader("Content-Type", "bad/type");
          httpResponse.AddHeader("Content-Disposition", "attachment; filename=questionnaire_details.csv");
          httpResponse.Write(strOutputHeader);
    
    
          Questionnaire questionnaire = new Questionnaire(intQuestionnaireID);
    
          List<Questionnaire> listQuestionnaire = Questionnaire.GetQuestionnairesByQuestionnaireID(intQuestionnaireID);
    
          strOutput = "\n";
          strOutput += "\"" + questionnaire.QuestionnaireName.Replace("\"", "'") + "\",";
          strOutput += "\"" + questionnaire.QuestionnaireDescription.Replace("\"", "'") + "\",";
          strOutput += "\"" + questionnaire.IntroText.Replace("\"", "'") + "\",";
          strOutput += "\"" + questionnaire.InstructionText.Replace("\"", "'") + "\",";
    
          strOutput += "\"" + questionnaire.Strapline.Replace("\"", "'") + "\",";
          strOutput += "\"" + questionnaire.Authors.Replace("\"", "'") + "\",";
          strOutput += "\"" + questionnaire.AddDate.ToString().Replace("\"", "'") + "\",";
          strOutput += "\"" + questionnaire.EditDate_Display.Replace("\"", "'") + "\",";
    
    
          httpResponse.Write(strOutput);
        }
      }
     
    Friday, March 27, 2009 9:00 AM

All replies

  • User-1171043462 posted

    Hi i have the following code which outputs data from my database onto an excel spread sheet, the problem is the data is going across, what i want to do is make it go into specific cells, for instance the question in Cell A and the answer in Cell B. How do i do this?

        public void DownloaQuestionnaireCSV(HttpResponse httpResponse, int intQuestionnaireID)
        {
          string strOutputHeader = "";
          string strOutput = "";
    
          strOutputHeader += "\"Questionnaire Name\",";
          strOutputHeader += "\"QuestionnaireDescription\",";
    
          strOutputHeader += "\"IntroText\",";
          strOutputHeader += "\"InstructionText\",";
    
          strOutputHeader += "\"Strapline\",";
          strOutputHeader += "\"Authors\",";
    
          strOutputHeader += "\"Add Date\",";
          strOutputHeader += "\"Edit Date\",";
    
    
          strOutputHeader += "\"Questions\",";
          strOutputHeader += "\"Answers\",";
    
    
          httpResponse.AddHeader("Content-Type", "bad/type");
          httpResponse.AddHeader("Content-Disposition", "attachment; filename=questionnaire_details.csv");
          httpResponse.Write(strOutputHeader);
    
    
          Questionnaire questionnaire = new Questionnaire(intQuestionnaireID);
    
          List<Questionnaire> listQuestionnaire = Questionnaire.GetQuestionnairesByQuestionnaireID(intQuestionnaireID);
    
          strOutput = "\n";
          strOutput += "\"" + questionnaire.QuestionnaireName.Replace("\"", "'") + "\",";
          strOutput += "\"" + questionnaire.QuestionnaireDescription.Replace("\"", "'") + "\",";
          strOutput += "\"" + questionnaire.IntroText.Replace("\"", "'") + "\",";
          strOutput += "\"" + questionnaire.InstructionText.Replace("\"", "'") + "\",";
    
          strOutput += "\"" + questionnaire.Strapline.Replace("\"", "'") + "\",";
          strOutput += "\"" + questionnaire.Authors.Replace("\"", "'") + "\",";
          strOutput += "\"" + questionnaire.AddDate.ToString().Replace("\"", "'") + "\",";
          strOutput += "\"" + questionnaire.EditDate_Display.Replace("\"", "'") + "\",";
    
    
          httpResponse.Write(strOutput);
        }
      }

    To export it to specific cells of excel  refer here

    http://support.microsoft.com/kb/316934

    Friday, March 27, 2009 9:47 AM