VC6.0 MFC程序,连接的数据库,现在想要输出一个这样的表格,并填入里面的数据,请问怎么做?
2.
WPS可以吗,或者EXCEL有版本要求吗,还是只要xls格式都可以?
3.本来是要把数据填入这个表格后打印输出的,但是打印这块还不会,所以想先直接输出个表格再打印成文件。如果有可以直接做成可打印并保存的方法就更好了,谢谢
9 个解决方案
#1
调用Excel虽说是一个方法,但是速度很慢;
建议楼主采用HTML文件的方法 ,就是把打印的内容根据HTML语法规则写到一个HTML文件里,然后调用浏览器打印这个HTML文件即可,非常方便
建议楼主采用HTML文件的方法 ,就是把打印的内容根据HTML语法规则写到一个HTML文件里,然后调用浏览器打印这个HTML文件即可,非常方便
#2
]
对对对,我也知道这个方法,但是不会啊,请问怎么做?在哪里有教吗
对对对,我也知道这个方法,但是不会啊,请问怎么做?在哪里有教吗
#3
就是怎么把MFC里面的数据,写到HTML的表格里呢
#4
使用报表控件可满足需求
#5
VC6 的MSDN的例子下有 EXCEL8, 可以参考
// Copyright (C) 1992-1998 Microsoft Corporation
// All rights reserved.
//
// This source code is only intended as a supplement to the
// Microsoft Visual C++ Language Reference and related
// electronic documentation provided with Microsoft Visual C++.
// See these sources for detailed information regarding the
// Microsoft Visual C++ product.
// NOTE: This example will only work with Excel8 in Office97
// Compile with cl /GX comexcel.cpp
// TO DO: Edit the #import paths
#import "MSO9.DLL" rename("RGB", "RBGMSO") rename("SearchPath", "SearchPathMSO") \
rename("DocumentProperties", "DocumentPropertiesMSO") no_auto_exclude
#import "VBE6EXT.OLB" no_namespace no_auto_exclude
#import "EXCEL9.OLB" rename("RGB", "RBGXL") rename("DialogBox", "DialogBoxXL") \
rename("CopyFile", "CopyFileXL") rename("ReplaceText", "ReplaceTextXL") rename("IPicture", "IPictureXL") \
rename("IFont", "IFontXL") rename("DocumentProperties", "DocumentPropertiesXL") no_dual_interfaces no_auto_exclude
#include <stdio.h>
#include <tchar.h>
void dump_com_error(_com_error &e)
{
_tprintf(_T("Oops - hit an error!\n"));
_tprintf(_T("\a\tCode = %08lx\n"), e.Error());
_tprintf(_T("\a\tCode meaning = %s\n"), e.ErrorMessage());
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());
_tprintf(_T("\a\tSource = %s\n"), (LPCTSTR) bstrSource);
_tprintf(_T("\a\tDescription = %s\n"), (LPCTSTR) bstrDescription);
}
// If this is placed in the scope of the smart pointers, they must be
// explicitly Release(d) before CoUninitialize() is called. If any reference
// count is non-zero, a protection fault will occur.
struct StartOle {
StartOle() { CoInitialize(NULL); }
~StartOle() { CoUninitialize(); }
} _inst_StartOle;
void main()
{
using namespace Excel;
_ApplicationPtr pXL;
try
{
pXL.CreateInstance(L"Excel.Application");
pXL->Visible = VARIANT_TRUE;
WorkbooksPtr pBooks = pXL->Workbooks;
_WorkbookPtr pBook = pBooks->Add((long)xlWorksheet);
_WorksheetPtr pSheet = pXL->ActiveSheet;
try {
// This one will fail
pSheet->Name = "Market Share?";
} catch (_com_error &e) {
dump_com_error(e);
}
pSheet->Name = "Market Share!";
//Fill A21:A26 with an array of values (First & Last Names).
{
SAFEARRAYBOUND numElements ={0,5}; //5 element array
SAFEARRAY *psa = SafeArrayCreate(VT_BSTR, 1, &numElements);
#define FillSafeArray(sz, i, sa) \
{ \
BSTR bv = SysAllocString(sz); \
LONG iRg = i; \
SafeArrayPutElement(sa, &iRg, bv); \
SysFreeString(bv); \
}
FillSafeArray(L"John", 0, psa);
FillSafeArray(L"Smith", 1, psa);
FillSafeArray(L"Tom", 2, psa);
FillSafeArray(L"Brown", 3, psa);
FillSafeArray(L"Sue", 4, psa);
RangePtr range = pSheet->GetRange("A20:A24");
range->PutValue(_variant_t(psa));
SafeArrayDestroy(psa);
}
pSheet->Range["A2"]->Value = "Company A";
pSheet->Range["B2"]->Value = "Company B";
pSheet->Range["C2"]->Value = "Company C";
pSheet->Range["D2"]->Value = "Company D";
pSheet->Range["A3"]->Value = 75.0;
pSheet->Range["B3"]->Value = 14.0;
pSheet->Range["C3"]->Value = 7.0;
pSheet->Range["D3"]->Value = 4.0;
Sleep(1000);
RangePtr pRange = pSheet->Range["A2:D3"];
_ChartPtr pChart = pBook->Charts->Add();
pChart->ChartWizard((Range*) pRange, (long) xl3DPie, 7L, (long) xlRows,
1L, 0L, 2L, "Market Share");
Sleep(6000);
pBook->Saved = VARIANT_TRUE;
pXL->Quit();
} catch(_com_error &e) {
dump_com_error(e);
}
}
#6
谢谢,我想用列表控件实现打印,我再看看
#7
方法1:下载EXCEL开发包
方法2:学习HTML表格,保存为xls就可以了
方法2:学习HTML表格,保存为xls就可以了
#8
怎么在对话框中实现打印和打印预览?比如打印一个列表控件
#9
已经会了,CSDN下载里面有例子,很不错
#1
调用Excel虽说是一个方法,但是速度很慢;
建议楼主采用HTML文件的方法 ,就是把打印的内容根据HTML语法规则写到一个HTML文件里,然后调用浏览器打印这个HTML文件即可,非常方便
建议楼主采用HTML文件的方法 ,就是把打印的内容根据HTML语法规则写到一个HTML文件里,然后调用浏览器打印这个HTML文件即可,非常方便
#2
]
对对对,我也知道这个方法,但是不会啊,请问怎么做?在哪里有教吗
对对对,我也知道这个方法,但是不会啊,请问怎么做?在哪里有教吗
#3
就是怎么把MFC里面的数据,写到HTML的表格里呢
#4
使用报表控件可满足需求
#5
VC6 的MSDN的例子下有 EXCEL8, 可以参考
// Copyright (C) 1992-1998 Microsoft Corporation
// All rights reserved.
//
// This source code is only intended as a supplement to the
// Microsoft Visual C++ Language Reference and related
// electronic documentation provided with Microsoft Visual C++.
// See these sources for detailed information regarding the
// Microsoft Visual C++ product.
// NOTE: This example will only work with Excel8 in Office97
// Compile with cl /GX comexcel.cpp
// TO DO: Edit the #import paths
#import "MSO9.DLL" rename("RGB", "RBGMSO") rename("SearchPath", "SearchPathMSO") \
rename("DocumentProperties", "DocumentPropertiesMSO") no_auto_exclude
#import "VBE6EXT.OLB" no_namespace no_auto_exclude
#import "EXCEL9.OLB" rename("RGB", "RBGXL") rename("DialogBox", "DialogBoxXL") \
rename("CopyFile", "CopyFileXL") rename("ReplaceText", "ReplaceTextXL") rename("IPicture", "IPictureXL") \
rename("IFont", "IFontXL") rename("DocumentProperties", "DocumentPropertiesXL") no_dual_interfaces no_auto_exclude
#include <stdio.h>
#include <tchar.h>
void dump_com_error(_com_error &e)
{
_tprintf(_T("Oops - hit an error!\n"));
_tprintf(_T("\a\tCode = %08lx\n"), e.Error());
_tprintf(_T("\a\tCode meaning = %s\n"), e.ErrorMessage());
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());
_tprintf(_T("\a\tSource = %s\n"), (LPCTSTR) bstrSource);
_tprintf(_T("\a\tDescription = %s\n"), (LPCTSTR) bstrDescription);
}
// If this is placed in the scope of the smart pointers, they must be
// explicitly Release(d) before CoUninitialize() is called. If any reference
// count is non-zero, a protection fault will occur.
struct StartOle {
StartOle() { CoInitialize(NULL); }
~StartOle() { CoUninitialize(); }
} _inst_StartOle;
void main()
{
using namespace Excel;
_ApplicationPtr pXL;
try
{
pXL.CreateInstance(L"Excel.Application");
pXL->Visible = VARIANT_TRUE;
WorkbooksPtr pBooks = pXL->Workbooks;
_WorkbookPtr pBook = pBooks->Add((long)xlWorksheet);
_WorksheetPtr pSheet = pXL->ActiveSheet;
try {
// This one will fail
pSheet->Name = "Market Share?";
} catch (_com_error &e) {
dump_com_error(e);
}
pSheet->Name = "Market Share!";
//Fill A21:A26 with an array of values (First & Last Names).
{
SAFEARRAYBOUND numElements ={0,5}; //5 element array
SAFEARRAY *psa = SafeArrayCreate(VT_BSTR, 1, &numElements);
#define FillSafeArray(sz, i, sa) \
{ \
BSTR bv = SysAllocString(sz); \
LONG iRg = i; \
SafeArrayPutElement(sa, &iRg, bv); \
SysFreeString(bv); \
}
FillSafeArray(L"John", 0, psa);
FillSafeArray(L"Smith", 1, psa);
FillSafeArray(L"Tom", 2, psa);
FillSafeArray(L"Brown", 3, psa);
FillSafeArray(L"Sue", 4, psa);
RangePtr range = pSheet->GetRange("A20:A24");
range->PutValue(_variant_t(psa));
SafeArrayDestroy(psa);
}
pSheet->Range["A2"]->Value = "Company A";
pSheet->Range["B2"]->Value = "Company B";
pSheet->Range["C2"]->Value = "Company C";
pSheet->Range["D2"]->Value = "Company D";
pSheet->Range["A3"]->Value = 75.0;
pSheet->Range["B3"]->Value = 14.0;
pSheet->Range["C3"]->Value = 7.0;
pSheet->Range["D3"]->Value = 4.0;
Sleep(1000);
RangePtr pRange = pSheet->Range["A2:D3"];
_ChartPtr pChart = pBook->Charts->Add();
pChart->ChartWizard((Range*) pRange, (long) xl3DPie, 7L, (long) xlRows,
1L, 0L, 2L, "Market Share");
Sleep(6000);
pBook->Saved = VARIANT_TRUE;
pXL->Quit();
} catch(_com_error &e) {
dump_com_error(e);
}
}
#6
谢谢,我想用列表控件实现打印,我再看看
#7
方法1:下载EXCEL开发包
方法2:学习HTML表格,保存为xls就可以了
方法2:学习HTML表格,保存为xls就可以了
#8
怎么在对话框中实现打印和打印预览?比如打印一个列表控件
#9
已经会了,CSDN下载里面有例子,很不错