=================================================================================
/******C语言打印EXCEL表格*********/
#include <stdio.h>
#include <stdlib.h>
#include "datrd.h"
int main()
{
/****/
int i,j, ret;
float fbuf[2880];
unsigned int fnum = 0;
long fstart = 0, fend = 0;
/***/
char *data;
char str1[10],str2[10],str3[10],str4[10],str5[10];
int setflag1,setflag2,setflag3,setflag4,setflag5;
char dbname[50];
data=getenv("QUERY_STRING");
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);
sprintf(dbname,"%d-%d-%d.db",setflag3,setflag4,setflag5);
ret = DatReadUaXbThd(dbname, 1, 2, fbuf, &fnum, &fstart, &fend);
if(ret == 0)
{
printf("Content-Disposition: attachment;filename=\"data.csv\"\n");
printf("Content-Type: application/x-xls\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;
}
/*******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);
window.open("/test/cgi-bin/save_data.cgi?"+check_str0);
}
else
{
alert("浏览器不支持,请更换浏览器!");
}
}
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>