我在PDFsharp中找不到文档来展示如何使用C#添加第二页!
例如,在VB6中,我使用名为mjwPDF的PDF创建方法.表示页面已完成
objPDF.PDFEndPage
Run Code Online (Sandbox Code Playgroud)
并开始一个新的页面:
objPDF.PDFNewPage
Run Code Online (Sandbox Code Playgroud)
我的PDFsharp初始设置:
// Create a new PDF document
PdfDocument document = new PdfDocument();
// Create an empty page
PdfPage page = document.AddPage();
//page.Contents.CreateSingleContent().Stream.UnfilteredValue;
// Get an XGraphics object for drawing
XGraphics gfx = XGraphics.FromPdfPage(page);
Run Code Online (Sandbox Code Playgroud)
不幸的是,在PDFsharp中我无法找到如何在新页面上开始/写入.我看到这些命令但无法启动第二页.
document.AddPage();
document.InsertPage();
Run Code Online (Sandbox Code Playgroud)
我已尝试过这两种方法,但我的输出继续写在第1页,而不是第2页.
任何想法将不胜感激.
这是实际的代码:
private void buttonPrint_Click(object sender, EventArgs e)
{
// Create a new PDF document
PdfDocument document = new PdfDocument();
// Create an empty page
PdfPage page = document.AddPage();
//page.Contents.CreateSingleContent().Stream.UnfilteredValue;
// Get an XGraphics object for drawing
XGraphics …Run Code Online (Sandbox Code Playgroud) 在我致力于疯人院之前,我想我会尝试一下:你如何编写代码来打印多个页面?
我一直在尝试我在stackoverflow(和其他地方)找到的所有例子,但我没有取得任何成功!这让我比以前更疯狂!我发现的所有其他例子都是处理与我想要做的事情无关的问题.我试图修复的示例将在两个页面上打印0-100个整数,即第1页的0-80和第2页的81-100.尽管所有我建议的技术都是一页被页面覆盖的页面2的数据在顶部.
e.HasMorePages = true; 应该开始下一页但不起作用.
我为此创建了一个非常简单的Winform程序,这是代码.任何想法将不胜感激:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Printing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
namespace PrintMultiplePages_v2
{
public partial class Form1 : Form
{
ArrayList al = new ArrayList();
private int fontcount;
private int fontposition = 1;
private float ypos;
private string textToPrint;
private PrintPreviewDialog previewDlg = null;
private PrintDocument pd = null;
private int counter = 0;
private int amtperpage = 80; // The amount of …Run Code Online (Sandbox Code Playgroud) 我被一个看起来很简单的问题难住了,标记 X 和 Y 轴!
我正在用 C# 在 VS2010 中创建一个 Excel 图表。它是一个二维 XY 散点图。但是我无法控制X轴的标签!我只能控制Y轴的标签!我花了太多时间试图解决这个问题并放弃了。所以我在找人帮忙!这是我的代码:
private void showExcelXY_v2()
{
xla = new Microsoft.Office.Interop.Excel.Application();
xla.Visible = true;
Workbook wb = xla.Workbooks.Add(XlSheetType.xlWorksheet);
Worksheet ws = (Worksheet)xla.ActiveSheet;
// Now create the chart.
ChartObjects chartObjs = (ChartObjects)ws.ChartObjects(Type.Missing);
ChartObject chartObj = chartObjs.Add(100, 20, 500, 300);
Microsoft.Office.Interop.Excel.Chart xlChart = chartObj.Chart;
//add some data from your datasource like a dataset or like below.
ws.Cells[1, 1] = "Value of n";
ws.Cells[1, 2] = "Term";
ws.Cells[2, 1] = "0";
ws.Cells[2, …Run Code Online (Sandbox Code Playgroud) 我需要一种通过 c# 读取 Excel 文件的方法。我找到了一个例子https://coderwall.com/p/app3ya/read-excel-file-in-c
我创建了一个独立的程序来测试它,它按我的预期工作。我将代码作为子程序添加到现有程序中并遇到错误。
第一个错误,“无法将类型‘对象’隐式转换为 Microsoft.Office.Interop.Excel._Worksheet。存在显式转换。”
第二个错误,“'Object' 不包含'Value2' 的定义”。
我通过将 (Excel._Worksheet) 添加到 xlWorkbook.Sheets[1] 修复了第一个错误;
我无法找出 Value2 上的第二个,需要您的帮助:“错误 98 'object' 不包含 'Value2' 的定义,并且找不到接受类型为 'object' 的第一个参数的扩展方法 'Value2' (您是否缺少 using 指令或程序集引用?)”
这是我的代码:
using System;
using System.Collections.Generic;
using System.Collections;ArrayList, ListBox, ComboBox, etc.
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using XView.Properties;
using System.Reflection;
using ZedGraph;
using System.IO;
using System.Management;
using System.Threading;
using System.Diagnostics;
using System.Runtime.InteropServices;
using Excel = Microsoft.Office.Interop.Excel;
private void readExcelFile(ArrayList al)
{
string rowItems …Run Code Online (Sandbox Code Playgroud)