Error while trying to save workbook as a stream

HI,

I am trying to save a workbook as a stream. while saving i get an error -

" Do not know how to write a property value of this type".

I have earlier tried to save workbook as stream and it has worked . Cant figure out y I am getting this error now. Could it be because of any discrepency in putting values to the cells or in formatting the values before inserting into the respected cells? Can u pls help me out?

Code Used :

Stream sw;

workbook.Save(sw, FileFormatType.Default);

I have sent the error message as an attachment.

It seems that a property in your Excel file cannot be recognized. Could you please post your template file here?

If you set properties at run time, please post your sample code here.

And if possible, a sample project will help us much to figure out your problem.

These are the properties that i am setting. before i save the workbook in a stream-

workbook.Worksheets.BuiltInDocumentProperties["Title"].Value = r.Title;

workbook.Worksheets.BuiltInDocumentProperties["Author"].Value = "Yotta";

workbook.Worksheets.BuiltInDocumentProperties["Company"].Value = "Hewlett Packard";

workbook.Worksheets.BuiltInDocumentProperties["Category"].Value = " ";

workbook.Worksheets.BuiltInDocumentProperties["Keywords"].Value = " ";

workbook.Worksheets.BuiltInDocumentProperties["Comments"].Value = " ";

workbook.Worksheets.BuiltInDocumentProperties["Subject"].Value = " ";

workbook.Worksheets.BuiltInDocumentProperties["Manager"].Value = " ";

workbook.Worksheets.BuiltInDocumentProperties["RevisionNumber"].Value = " ";

It would not be possible for me to send an applciation. However i'll put in some part of the code which binds data to the cells .

if (tp == typeof(MatrixCell))

{

stringformat(t, cells[curRow, curCol]);

setStyles(tb.Style, cells[curRow, curCol]);

}

else if (tp == typeof(DynamicColumns) || tp == typeof(DynamicRows))

{

cells[curRow, curCol].PutValue(t);

setStyles(tb.Style, cells[curRow, curCol]);

}

private void stringformat(string t,Cell cell)

{

//if 't' has '$' as prefix, convert to currency fromat

if (t.StartsWith("$"))

{

double curr = double.Parse(t.Substring(1));

cell.PutValue(curr);

cell.Style.Number = 12;

cell.Style.Custom = "$#,##0.00_);($#,##0.00)";

return;

}

//if 't' is neumeric, convert to integer

if (IsNumeric(t))

{

cell.PutValue(int.Parse(t));

return;

}

cell.PutValue(t);

}

private bool IsNumeric(string strCheck)

{

try

{

int.Parse(strCheck);

return true;

}

catch

{

return false;

}

}

public void setStyles(Style itemStyle, Cell cell)

{

//set borders

Border borderRt = cell.Style.Borders[BorderType.RightBorder];

Border borderLt = cell.Style.Borders[BorderType.LeftBorder];

Border borderTp = cell.Style.Borders[BorderType.TopBorder];

Border borderBtm = cell.Style.Borders[BorderType.BottomBorder];

//background colors

if (itemStyle.BackgroundColor != null)

{

//If the color is not a known color, set the palette with the color before using it

workbook.ChangePalette(System.Drawing.ColorTranslator.FromHtml(itemStyle.BackgroundColor.Source), 55);

cell.Style.Pattern = BackgroundType.Gray6;

cell.Style.BackgroundColor = System.Drawing.ColorTranslator.FromHtml(itemStyle.BackgroundColor.Source);

}

//font styles

if (itemStyle.FontFamily != null)

cell.Style.Font.Name = itemStyle.FontFamily.Source;

if (itemStyle.FontSize != null)

cell.Style.Font.Size = short.Parse((itemStyle.FontSize.Source).Substring(0, ((itemStyle.FontSize.Source).IndexOf('p', 0))));

if (itemStyle.FontWeight != null)

{

if (itemStyle.FontWeight.Source == "Bold")

{

cell.Style.Font.IsBold = true;

}

else

{

cell.Style.Font.IsBold = false;

}

}

//set border style

if (itemStyle.BorderStyle != null)

{

workbook.ChangePalette(System.Drawing.ColorTranslator.FromHtml(itemStyle.BorderColor.Default.Source), 54);

if (itemStyle.BorderStyle.Default.Source == "Solid")

{

borderRt.LineStyle = CellBorderType.Medium;

borderRt.Color = System.Drawing.ColorTranslator.FromHtml(itemStyle.BorderColor.Default.Source);

borderLt.LineStyle = CellBorderType.Medium;

borderLt.Color = System.Drawing.ColorTranslator.FromHtml(itemStyle.BorderColor.Default.Source);

borderTp.LineStyle = CellBorderType.Medium;

borderTp.Color = System.Drawing.ColorTranslator.FromHtml(itemStyle.BorderColor.Default.Source);

borderBtm.LineStyle = CellBorderType.Medium;

borderBtm.Color = System.Drawing.ColorTranslator.FromHtml(itemStyle.BorderColor.Default.Source);

}

}

//font color

//cell.Style.Font.Color = System.Drawing.ColorTranslator.FromHtml(r.Style.Color.Source);

//text alignment

if (itemStyle.TextAlign != null)

{

switch (itemStyle.TextAlign.Source)

{

case "Left": cell.Style.HorizontalAlignment = TextAlignmentType.Left;

break;

case "Right": cell.Style.HorizontalAlignment = TextAlignmentType.Right;

break;

case "Center": cell.Style.HorizontalAlignment = TextAlignmentType.Center;

break;

}

}

}

Regards,

Soumya

Sorry i forgot to upload the template fileā€¦ i have sent one now

Is it possible that r.Title is null? How about change your code to:

if(r.Title != null)

workbook.Worksheets.BuiltInDocumentProperties["Title"].Value = r.Title;

yes that was the error, i checked r.Title for null before saving. It works fine now. Thanks

Regards,

Soumya