/* SciGraphica - Scientific graphics and data manipulation * Copyright (C) 2001 Adrian E. Feiguin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include #include #include #include "sg_worksheet_file_html.h" #include "sg.h" static void write_header_html (SGworksheetfile *file); static void write_footer_html (SGworksheetfile *file); static void write_col_title_html (SGworksheetfile *file, gint col); static void write_row_title_html (SGworksheetfile *file, gint row); static void write_cell_html (SGworksheetfile *file, gint row, gint col); static void new_row_html (SGworksheetfile *file, gint row); static void justify_html (SGworksheetfile *file, GtkJustification just); gboolean sg_worksheet_file_export_html (SGworksheet *worksheet, gchar *filename, GtkSheetRange *range) { SGworksheetfile *file; GtkSheet *sheet; sheet = GTK_SHEET(worksheet->sheet); file = sg_worksheet_file_new(worksheet, filename); if ((file->file = fopen(file->filename, "w")) == NULL){ g_warning("ERROR: Cannot write to file: %s", filename); g_free(file); return FALSE; } file->write_header = write_header_html; file->write_footer = write_footer_html; file->write_col_title = write_col_title_html; file->write_row_title = write_row_title_html; file->write_cell = write_cell_html; file->new_row = new_row_html; file->titlecolor = g_strdup("\"BBBBBB\""); file->cellcolor = g_strdup("\"FFFFFF\""); sg_worksheet_file_export(file, range); fclose(file->file); g_free(file->filename); g_free(file->titlecolor); g_free(file->cellcolor); g_free(file); return TRUE; } static void write_header_html(SGworksheetfile *file) { fprintf(file->file,"\n"); fprintf(file->file,"\n"); fprintf(file->file, "\n"); fprintf(file->file, " \n"); fprintf(file->file, "\n"); fprintf(file->file,"\n", file->titlecolor); } static void write_footer_html(SGworksheetfile *file) { fprintf(file->file, "\n\n"); fprintf(file->file, "

\n\n"); fprintf(file->file,"\n"); fprintf(file->file,"\n"); } static void new_row_html(SGworksheetfile *file, gint row) { fprintf(file->file, "\n"); fprintf(file->file, "\n"); } static void write_col_title_html(SGworksheetfile *file, gint col) { gchar *title; title = GTK_SHEET(file->worksheet->sheet)->column[col].name; fprintf(file->file, "titlecolor); justify_html(file, GTK_JUSTIFY_CENTER); if(title && strlen(title) > 0) fprintf(file->file, ">\n %s \n", title); else fprintf(file->file, ">\n
\n"); } static void write_row_title_html(SGworksheetfile *file, gint row) { gchar *title; title = GTK_SHEET(file->worksheet->sheet)->row[row].name; fprintf(file->file, "titlecolor); justify_html(file, GTK_JUSTIFY_CENTER); if(title && strlen(title) > 0) fprintf(file->file, ">\n %s \n", title); else fprintf(file->file, ">\n
\n"); } static void write_cell_html(SGworksheetfile *file, gint row, gint col) { gchar *text; GtkSheetCellAttr attr; gchar *xml_text = NULL; text = sg_worksheet_cell_get_text(file->worksheet, row, col); gtk_sheet_get_attributes(GTK_SHEET(file->worksheet->sheet), row, col, &attr); fprintf(file->file, "cellcolor); justify_html(file, attr.justification); if(text && strlen(text) > 0){ xml_text = xml_get_string(text); fprintf(file->file, ">\n %s \n", xml_text); g_free(xml_text); } else fprintf(file->file, ">\n
\n"); } static void justify_html(SGworksheetfile *file, GtkJustification just) { switch (just) { case GTK_JUSTIFY_LEFT: fprintf(file->file, "ALIGN=LEFT"); break; case GTK_JUSTIFY_RIGHT: fprintf(file->file, "ALIGN=RIGHT"); break; case GTK_JUSTIFY_CENTER: fprintf(file->file, "ALIGN=CENTER"); break; case GTK_JUSTIFY_FILL: default: break; } }