HTML:C语言打印excel表格并在HTML上点击保存


=================================================================================

/******C语言打印EXCEL表格*********/
#include <stdio.h>
#include <stdlib.h>
#include "datrd.h"

int main()
{
//printf("00000000000000000000\n");
/****/
    int i,j, ret;
    float fbuf[2880];
    unsigned int fnum = 0;
    long fstart = 0, fend = 0;
/***/
/*get data from javascript*/
  char *data;
  char str1[10],str2[10],str3[10],str4[10],str5[10];
  int setflag1,setflag2,setflag3,setflag4,setflag5;
  char dbname[50];
//printf("AAAAAAAAAAAAAAAAAAAAAAAAAAAaa");
  data=getenv("QUERY_STRING");
  //char *data="5&flag2=1&flag3=2015&flag4=9&flag5=15&cur_time142332342422";
  sscanf(data,"%[^&]&flag2=%[^&]&flag3=%[^&]&flag4=%[^&]&flag5=%[^&]&",str1,str2,str3,str4,str5);

  setflag1=atoi(str1);
  setflag2=atoi(str2);  
  setflag3=atoi(str3);
  setflag4=atoi(str4);
  setflag5=atoi(str5);
 // printf("111111111111111111\n");
    //读取

        sprintf(dbname,"%d-%d-%d.db",setflag3,setflag4,setflag5);


       //printf("222222222222222\n");
    ret = DatReadUaXbThd(dbname, 1, 2, fbuf, &fnum, &fstart, &fend);
    //printf("3333333333333333\n");
    if(ret == 0)
    {
        //printf("444444444444444\n");
        //printf("get %d records,start = %ld, end = %ld\n", fnum, fstart, fend);

               printf("Content-Disposition: attachment;filename=\"data.csv\"\n");
               printf("Content-Type: application/x-xls\n\n");
        //printf("Content-Type: text/html\n\n");
               printf("起始时间:%ld\n", fstart);
           printf("结束时间:%ld\n", fend);
               printf("索引, 数值\n");
        for(i = 0; i < fnum; i++)
        {
            printf("%d, %f\n", i, fbuf[i]);
        }
        printf("\n");
    }
       return 0;

    //printf("%d|%d|%d|%d|%d\n",setflag1,setflag2,setflag3,setflag4,setflag5);
}

/*******JS程序********/
function save_data()
{
    if(g_flag==-1) return;
    var flag1=g_flag;
    xhr_set_0 = createXHR();
    if(xhr_set_0)
    {  
        var  check_str0 = flag1;
        check_str0 = check_str0 +"&flag2=";
        check_str0 = check_str0 +document.getElementById("page"+flag1).value;
        check_str0 = check_str0 +"&flag3=";
        check_str0 = check_str0 +document.getElementById("year").value;
        check_str0 = check_str0 +"&flag4=";
        check_str0 = check_str0 +document.getElementById("month").value;
        check_str0 = check_str0 +"&flag5=";
        check_str0 = check_str0 +document.getElementById("day").value;
        check_str0 = check_str0 +"&cur_time";
        check_str0 = check_str0 + new Date().getTime();
        alert(check_str0);
        //xhr_set_0.open("GET", "/test/cgi-bin/save_data.cgi?" + check_str0);
        //xhr_set_0.send(null); 
        //xhr_set_0.onreadystatechange = callbackFunction_save;
        window.open("/test/cgi-bin/save_data.cgi?"+check_str0);
      }

    else
    {
        alert("浏览器不支持,请更换浏览器!");
    }
}

//http://192.168.1.11/test/cgi-bin/save_data.cgi?5&flag2=1&flag3=2015&flag4=9&flag5=15&cur_time142332342422


function callbackFunction_save()
{  
    if (xhr_set_0.readyState == 4)
    {
        if (xhr_set_0.status == 200)
        {                

            var returnValue = xhr_set_0.responseText;
            if(returnValue != null && returnValue.length > 0)
            {      
                alert(returnValue);
            }
            else
            {
             alert("访问数据为空!");
            }
        }
        else
        {
         alert("页面数据交互异常!");
        }
    }
}
 /*********html程序***************/
<td><input type="button" onclick="save_data()" value="保存数据"/></td>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值