private int m_currentPageIndex;
private IList<Stream> m_streams; private DataTable LoadSalesData()
{
DataTable table = new DataTable();
table.Columns.Add(new DataColumn("Name"));
DataRow row = table.NewRow();
row["Name"] = "测试";
table.Rows.Add(row);
return table;
} private Stream CreateStream(string name,
string fileNameExtension, Encoding encoding,
string mimeType, bool willSeek)
{
Stream stream = new FileStream(@"c:\My Reports\" + name +
"." + fileNameExtension, FileMode.Create);
m_streams.Add(stream);
return stream;
} private void Export(LocalReport report)
{
string deviceInfo =
" <DeviceInfo>" +
" <OutputFormat>EMF </OutputFormat>" +
" <PageWidth>8.5in </PageWidth>" +
" <PageHeight>11in </PageHeight>" +
" <MarginTop>0.25in </MarginTop>" +
" <MarginLeft>0.25in </MarginLeft>" +
" <MarginRight>0.25in </MarginRight>" +
" <MarginBottom>0.25in </MarginBottom>" +
" </DeviceInfo>";
Warning[] warnings;
m_streams = new List<Stream>();
report.Render("Image", deviceInfo, CreateStream, out warnings);//再此处出错: "本地报表处理期间出错。" 如何解决呢请高人指点
foreach (Stream stream in m_streams)
stream.Position = 0;
} private void PrintPage(object sender, PrintPageEventArgs ev)
{
Metafile pageImage = new Metafile(m_streams[m_currentPageIndex]);
ev.Graphics.DrawImage(pageImage, ev.PageBounds); m_currentPageIndex++;
ev.HasMorePages = (m_currentPageIndex < m_streams.Count);
} private void Print()
{
const string printerName = "Microsoft Office Document Image Writer"; if (m_streams == null || m_streams.Count == 0)
return; PrintDocument printDoc = new PrintDocument();
printDoc.PrinterSettings.PrinterName = printerName;
if (!printDoc.PrinterSettings.IsValid)
{
string msg = String.Format("Can't find printer \"{0}\".", printerName);
MessageBox.Show(msg, "Print Error");
return;
}
printDoc.PrintPage += new PrintPageEventHandler(PrintPage);
printDoc.Print();
} private void Run()
{
LocalReport report = new LocalReport();
report.ReportPath = @"D:\CaseCode\Rdlc报表\Rdlc报表\Report1.rdlc";
report.DataSources.Add(new ReportDataSource("Sales", LoadSalesData()));
Export(report);
m_currentPageIndex = 0;
Print();
}
private void button1_Click(object sender, EventArgs e)
{
Run();
}
private IList<Stream> m_streams; private DataTable LoadSalesData()
{
DataTable table = new DataTable();
table.Columns.Add(new DataColumn("Name"));
DataRow row = table.NewRow();
row["Name"] = "测试";
table.Rows.Add(row);
return table;
} private Stream CreateStream(string name,
string fileNameExtension, Encoding encoding,
string mimeType, bool willSeek)
{
Stream stream = new FileStream(@"c:\My Reports\" + name +
"." + fileNameExtension, FileMode.Create);
m_streams.Add(stream);
return stream;
} private void Export(LocalReport report)
{
string deviceInfo =
" <DeviceInfo>" +
" <OutputFormat>EMF </OutputFormat>" +
" <PageWidth>8.5in </PageWidth>" +
" <PageHeight>11in </PageHeight>" +
" <MarginTop>0.25in </MarginTop>" +
" <MarginLeft>0.25in </MarginLeft>" +
" <MarginRight>0.25in </MarginRight>" +
" <MarginBottom>0.25in </MarginBottom>" +
" </DeviceInfo>";
Warning[] warnings;
m_streams = new List<Stream>();
report.Render("Image", deviceInfo, CreateStream, out warnings);//再此处出错: "本地报表处理期间出错。" 如何解决呢请高人指点
foreach (Stream stream in m_streams)
stream.Position = 0;
} private void PrintPage(object sender, PrintPageEventArgs ev)
{
Metafile pageImage = new Metafile(m_streams[m_currentPageIndex]);
ev.Graphics.DrawImage(pageImage, ev.PageBounds); m_currentPageIndex++;
ev.HasMorePages = (m_currentPageIndex < m_streams.Count);
} private void Print()
{
const string printerName = "Microsoft Office Document Image Writer"; if (m_streams == null || m_streams.Count == 0)
return; PrintDocument printDoc = new PrintDocument();
printDoc.PrinterSettings.PrinterName = printerName;
if (!printDoc.PrinterSettings.IsValid)
{
string msg = String.Format("Can't find printer \"{0}\".", printerName);
MessageBox.Show(msg, "Print Error");
return;
}
printDoc.PrintPage += new PrintPageEventHandler(PrintPage);
printDoc.Print();
} private void Run()
{
LocalReport report = new LocalReport();
report.ReportPath = @"D:\CaseCode\Rdlc报表\Rdlc报表\Report1.rdlc";
report.DataSources.Add(new ReportDataSource("Sales", LoadSalesData()));
Export(report);
m_currentPageIndex = 0;
Print();
}
private void button1_Click(object sender, EventArgs e)
{
Run();
}
xp下IIS运行的用户是ASPNET
WIN2003下是NETWORK SERVICE