=================================================================================
/******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>
HTML:C语言打印excel表格并在HTML上点击保存
最新推荐文章于 2023-12-02 11:11:02 发布