コード例 #1
0
        private void WriteQuestionIntoExcel(DIExcel excelFile, Question xmlQuestion, ref int RowIndex)
        {
            int    DataValueRowIndex = RowIndex + 1;
            int    BoldStartIndex    = -1;
            int    BoldEndIndex      = -1;
            int    ItalicStartIndex  = -1;
            int    ItalicEndIndex    = -1;
            string BoldStartTag      = "<b>";
            string ItalicStartTag    = "<i>";
            string BoldEndTag        = "</b>";
            string ItalicEndTag      = "</i>";
            string QuestionText      = xmlQuestion.Text;

            //set question no and question text
            excelFile.SetCellValue(Constants.SheetIndex, RowIndex, Constants.QuestionNoColumnIndex, xmlQuestion.No);
            excelFile.SetColumnWidth(Constants.SheetIndex, 6, RowIndex, Constants.QuestionNoColumnIndex, RowIndex, Constants.QuestionNoColumnIndex);
            //replace <br> with new line character and remove enter key

            QuestionText = QuestionText.Replace(Char.ConvertFromUtf32(13), string.Empty);

            QuestionText = QuestionText.Replace("\n", string.Empty);
            QuestionText = QuestionText.Replace(Microsoft.VisualBasic.ControlChars.CrLf, string.Empty);
            QuestionText = QuestionText.Replace(Microsoft.VisualBasic.ControlChars.Lf.ToString(), string.Empty);
            QuestionText = QuestionText.Replace("<br>", Microsoft.VisualBasic.ControlChars.NewLine);

            //apply bold tag
            BoldStartIndex = QuestionText.IndexOf(BoldStartTag);
            if (BoldStartIndex >= 0)
            {
                QuestionText = QuestionText.Replace(BoldStartTag, string.Empty);
                BoldEndIndex = QuestionText.IndexOf(BoldEndTag);
                QuestionText = QuestionText.Replace(BoldEndTag, string.Empty);
            }

            //apply italic tag
            ItalicStartIndex = QuestionText.IndexOf(ItalicStartTag);
            if (ItalicStartIndex >= 0)
            {
                QuestionText   = QuestionText.Replace(ItalicStartTag, string.Empty);
                ItalicEndIndex = QuestionText.IndexOf(ItalicEndTag);
                QuestionText   = QuestionText.Replace(ItalicEndTag, string.Empty);
            }

            //set question text
            QuestionText.Replace(ItalicStartTag, string.Empty);
            excelFile.SetCellValue(Constants.SheetIndex, RowIndex, Constants.QuestionTextColumnIndex, QuestionText);

            //set bold
            if (BoldStartIndex >= 0 & BoldEndIndex >= 0)
            {
                excelFile.GetCellCharacters(Constants.SheetIndex, Constants.QuestionTextColumnIndex, RowIndex, BoldStartIndex, BoldEndIndex - BoldStartIndex).Font.Bold = true;
            }

            //set italic
            if (ItalicStartIndex >= 0 & ItalicEndIndex >= 0)
            {
                excelFile.GetCellCharacters(Constants.SheetIndex, Constants.QuestionTextColumnIndex, RowIndex, ItalicStartIndex, ItalicEndIndex - ItalicStartIndex).Font.Italic = true;
            }


            //set layout of question text cell and question no cell
            //excelFile.MergeCells(Constants.SheetIndex, RowIndex, Constants.QuestionTextColumnIndex, RowIndex, Constants.QuestionTextColumnIndex + 6);
            //excelFile.SetHorizontalAlignment(Constants.SheetIndex, RowIndex, Constants.QuestionTextColumnIndex, SpreadsheetGear.HAlign.Justify);
            //excelFile.SetVerticalAlignment(Constants.SheetIndex, RowIndex, Constants.QuestionTextColumnIndex, SpreadsheetGear.VAlign.Justify);
            //excelFile.GetCellFont(Constants.SheetIndex, RowIndex, Constants.QuestionTextColumnIndex).Bold = true;

            excelFile.GetCellFont(Constants.SheetIndex, RowIndex, Constants.QuestionNoColumnIndex).Bold = true;
            excelFile.AutoFitColumn(Constants.SheetIndex, Constants.QuestionNoColumnIndex);


            this.WriteDataValue(excelFile, xmlQuestion, ref DataValueRowIndex);

            RowIndex = DataValueRowIndex + 2;
        }