HTMLResult = cos_CreateEmpty(cnx);
cos_AppendString(cnx, HTMLResult, "<TABLE id=table BORDER=5>\n");
// obtain column ids
__CREATE_QUERY("SELECT id,align,fontsize,textcolor,fontfamily,textstyle,name FROM co_%s_spreadsheet_column WHERE spreadsheet_id=%d ORDER BY column_number",par_area,par_id);
__SQL_GET_RESULT
cols = cor_GetTupleCount(cnx, corec);
// column attributes
cos_AppendString(cnx, HTMLResult, "<COL width=30 align=center>\n");
cos_AppendString(cnx, HTMLResult, "<COLGROUP width=100>\n");
for (i=0;i<cols;i++)
{
cos_AppendString(cnx, HTMLResult, "<COL ");
if (strcmp(cor_GetValue(cnx, corec,i,1),"")) cos_AppendFormatted(cnx, HTMLResult, " align=%s", cor_GetValue(cnx, corec,i,1));
cos_AppendString(cnx, HTMLResult, " style='");
if (strcmp(cor_GetValue(cnx, corec,i,3),"")) cos_AppendFormatted(cnx, HTMLResult, "color:%s", cor_GetValue(cnx, corec,i,3));
if (strcmp(cor_GetValue(cnx, corec,i,4),"")) cos_AppendFormatted(cnx, HTMLResult, ";font-family:%s", cor_GetValue(cnx, corec,i,4));
if (strcmp(cor_GetValue(cnx, corec,i,2),"")) cos_AppendFormatted(cnx, HTMLResult, ";font-size:%s", cor_GetValue(cnx, corec,i,2));
strncpy(textstyle,cor_GetValue(cnx, corec,i,5),3);
if (textstyle[0]=='B') cos_AppendString(cnx, HTMLResult, ";font-weight:700");
if (textstyle[1]=='I') cos_AppendString(cnx, HTMLResult, ";font-style:italic");
if (textstyle[2]=='U') cos_AppendString(cnx, HTMLResult, ";text-decoration:underline");
cos_AppendString(cnx, HTMLResult, "' >\n");
}
cos_AppendString(cnx, HTMLResult, "</COLGROUP>\n");
// first row with column names ...
cos_AppendString(cnx, HTMLResult, "<TR bgcolor=LightGrey align=center>\n<TD></TD>\n");
for (i=0;i<cols;i++)
{
cos_AppendString(cnx, HTMLResult, "<TD bgcolor=F0F0F0 style='font-family:verdana' align=center");
if (strcmp(cor_GetValue(cnx, corec,i,6),"")) cos_AppendFormatted(cnx, HTMLResult, ">%s", cor_GetValue(cnx, corec,i,6));
else
{
j = i;
pos = 0;
// 26 is number of characters in english alphabet
while (j>=26)
{
// 65 is an ASCI code for first letter of an alphabet
column_abr[pos++] = (char) (65+(j % 26));
j /= 26; j--;
}
column_abr[pos] = (char) (65+j);
cos_AppendString(cnx, HTMLResult, ">");
while (pos>=0) cos_AppendFormatted(cnx, HTMLResult, "%c", column_abr[pos--]);
}
cos_AppendString(cnx, HTMLResult, "</TD>\n");
}
__CLEAR_RESULT
cos_AppendString(cnx, HTMLResult, "</TR>\n");
// read spreadsheet data from database
@co_call(par_area, par_class,"get", par_area=>par_area, par_class=>par_class, par_id=>par_id);
__GET_RETURNED_RECORDSET( corec)
// obtain row attributes
__CREATE_QUERY("SELECT id,align,fontsize,textcolor,fontfamily,textstyle,name FROM co_%s_spreadsheet_row WHERE spreadsheet_id=%d ORDER BY row_number", par_area, par_id);
__SQL_GET_VRESULT(corec2)
rows = cor_GetTupleCount(cnx, corec2);
// translate data into HTML
pos = 0;
for (i=1;i<=rows;i++)
{
// row style
cos_AppendString(cnx, HTMLResult, "<TR bgcolor=white");
if (strcmp(cor_GetValue(cnx, corec2,i-1,1),"")) cos_AppendFormatted(cnx, HTMLResult, " align=%s", cor_GetValue(cnx, corec2,i-1,1));
cos_AppendString(cnx, HTMLResult, " style='");
if (strcmp(cor_GetValue(cnx, corec2,i-1,3),"")) cos_AppendFormatted(cnx, HTMLResult, "color:%s", cor_GetValue(cnx, corec2,i-1,3));
if (strcmp(cor_GetValue(cnx, corec2,i-1,4),"")) cos_AppendFormatted(cnx, HTMLResult, ";font-family:%s", cor_GetValue(cnx, corec2,i-1,4));
if (strcmp(cor_GetValue(cnx, corec2,i-1,2),"")) cos_AppendFormatted(cnx, HTMLResult, ";font-size:%s",cor_GetValue(cnx, corec2,i-1,2));
strncpy(textstyle,cor_GetValue(cnx, corec2,i-1,5),3);
if (textstyle[0]=='B') cos_AppendString(cnx, HTMLResult, ";font-weight:700");
if (textstyle[1]=='I') cos_AppendString(cnx, HTMLResult, ";font-style:italic");
if (textstyle[2]=='U') cos_AppendString(cnx, HTMLResult, ";text-decoration:underline");
if (!strcmp("",cor_GetValue(cnx, corec2,i-1,6)))
{
// column obtains default name
cos_AppendFormatted(cnx, HTMLResult, "' bordercolor=MistyRose>\n<TD bgcolor=F0F0F0 style='font-family:verdana'>%d</TD>\n",i);
}
else
{
// column obtains defined name
cos_AppendFormatted(cnx, HTMLResult, "' bordercolor=MistyRose>\n<TD bgcolor=F0F0F0 style='font-family:verdana'>%s</TD>\n", cor_GetValue(cnx, corec2,i-1,6));
}
for (j=1;j<=cols;j++)
{
if (pos==cor_GetTupleCount(cnx, corec)) cos_AppendString(cnx, HTMLResult, "<TD>.</TD>\n");
else
{
if ((i==atoi(cor_GetValue(cnx, corec,pos,1))) && (j==atoi(cor_GetValue(cnx, corec,pos,0))))
{
cos_AppendString(cnx, HTMLResult, "<TD");
if (strcmp(cor_GetValue(cnx, corec,pos,3),"")) cos_AppendFormatted(cnx, HTMLResult, " align=%s", cor_GetValue(cnx, corec,pos,3));
cos_AppendString(cnx, HTMLResult, " style='");
if (strcmp(cor_GetValue(cnx, corec,pos,5),"")) cos_AppendFormatted(cnx, HTMLResult, "color:%s", cor_GetValue(cnx, corec,pos,5));
if (strcmp(cor_GetValue(cnx, corec,pos,6),"")) cos_AppendFormatted(cnx, HTMLResult, ";font-family:%s", cor_GetValue(cnx, corec,pos,6));
if (strcmp(cor_GetValue(cnx, corec,pos,4),"")) cos_AppendFormatted(cnx, HTMLResult, ";font-size:%s", cor_GetValue(cnx, corec,pos,4));
strncpy(textstyle,cor_GetValue(cnx, corec,pos,7),3);
if (textstyle[0]=='B') cos_AppendString(cnx, HTMLResult, ";font-weight:700");
if (textstyle[1]=='I') cos_AppendString(cnx, HTMLResult, ";font-style:italic");
if (textstyle[2]=='U') cos_AppendString(cnx, HTMLResult, ";text-decoration:underline");
cell_value = ap_escape_html(p, cor_GetValue(cnx, corec,pos,2));
if (strcmp(cell_value,"")) cos_AppendFormatted(cnx, HTMLResult, "'>%s</TD>\n", cell_value);
else cos_AppendString(cnx, HTMLResult, "'>.</TD>\n");
pos++;
}
else cos_AppendString(cnx, HTMLResult, "<TD>.</TD>\n");
}
}
cos_AppendString(cnx, HTMLResult, "</TR>\n");
}
cos_AppendString(cnx, HTMLResult, "</TABLE>\n");
__CLEAR_RESULT
cor_Clear(cnx, corec2);
__RETURN_STRING(cos_GetSimplifiedString(cnx, HTMLResult))