سلام
چه جوری میتونم از یه لیست ویو خروجی اکسل بگیرم
یا به pdf تبدیلش کنم ...
هر دو مورد رو لازم دارم لطفا راهنمایی کنید
سلام
چه جوری میتونم از یه لیست ویو خروجی اکسل بگیرم
یا به pdf تبدیلش کنم ...
هر دو مورد رو لازم دارم لطفا راهنمایی کنید
کوووووممممممممممککککککککک ککک
سلام
برای انتقال محتوای گرید به ایکسل :
بعد از اینکه Interop.Office و یه چند تای دیگه که در تصویر اومده رو به رفرنس اضافه کردین در رویداد کلیک یک با تن اینطور می نویسین :
private void btn_export_Click(object sender, EventArgs e)
{
Microsoft.Office.Interop.Excel._Application app = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel._Workbook workbook = app.Workbooks.Add(Type.Missing);
Microsoft.Office.Interop.Excel._Worksheet worksheet = null;
app.Visible = true;
try
{
worksheet = (Microsoft.Office.Interop.Excel.Worksheet)workbook .Sheets["Sheet1"];
worksheet = (Microsoft.Office.Interop.Excel.Worksheet)workbook .ActiveSheet;
worksheet.Name = "Exported from DataGridView";
for (int i = 1; i < DataGridView1.Columns.Count + 1; i++)
{
worksheet.Cells[1, i] = DataGridView1.Columns[i - 1].HeaderText;
}
for (int i = 0; i < DataGridView1.Rows.Count - 1; i++)
{
for (int j = 0; j < DataGridView1.Columns.Count; j++)
{
worksheet.Cells[i + 2, j + 1] = DataGridView1.Rows[i].Cells[j].Value.ToString();
}
}
string fileName = String.Empty;
saveFileExcel.Filter = "Excel files |*.xls|All files (*.*)|*.*";
saveFileExcel.FilterIndex = 2;
saveFileExcel.RestoreDirectory = true;
if (saveFileExcel.ShowDialog() == DialogResult.OK)
{
fileName = saveFileExcel.FileName;
workbook.SaveAs(fileName, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode. xlExclusive, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
}
else
return;
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
app.Quit();
workbook = null;
app = null;
}
}
این هم برای listview :
Microsoft.Office.Interop.Excel.Application xla = new Microsoft.Office.Interop.Excel.Application();
xla.Visible = true;
Microsoft.Office.Interop.Excel.Workbook wb = xla.Workbooks.Add(Microsoft.Office.Interop.Excel.X lSheetType.xlWorksheet);
Microsoft.Office.Interop.Excel.Worksheet ws = (Microsoft.Office.Interop.Excel.Worksheet)xla.Acti veSheet;
int i = 1;
int j = 1;
foreach (ListViewItem comp in listView1.Items)
{
ws.Cells[i, j] = comp.Text.ToString();
//MessageBox.Show(comp.Text.ToString());
foreach (ListViewItem.ListViewSubItem drv in comp.SubItems)
{
ws.Cells[i, j] = drv.Text.ToString();
j++;
}
j = 1;
i++;
}
pdf چه جوریه ؟؟؟
من این کدو برا pdf پیدا کردم اما کار نمیکنه :
oleDbConnection1.Open();
this.cellExport1.ActionAfterExport = DataExport.Common.ActionType.None;
this.cellExport1.DataFormats.CultureName = "zh-CN";
this.cellExport1.DataFormats.Currency = "?#,###,##0.00";
this.cellExport1.DataFormats.DateTime = "yyyy-M-d H:mm";
this.cellExport1.DataFormats.Float = "#,###,##0.00";
this.cellExport1.DataFormats.Integer = "#,###,##0";
this.cellExport1.DataFormats.Time = "H:mm";
this.cellExport1.SheetOptions.AggregateFormat.Font .Name = "Arial";
this.cellExport1.SheetOptions.CustomDataFormat.Fon t.Name = "Arial";
this.cellExport1.SheetOptions.DefaultFont.Name = "Arial";
this.cellExport1.SheetOptions.FooterFormat.Font.Na me = "Arial";
this.cellExport1.SheetOptions.HeaderFormat.Font.Na me = "Arial";
this.cellExport1.SheetOptions.HyperlinkFormat.Font .Color = Spire.DataExport.XLS.CellColor.Blue;
this.cellExport1.SheetOptions.HyperlinkFormat.Font .Name = "Arial";
this.cellExport1.SheetOptions.HyperlinkFormat.Font .Underline = Spire.DataExport.XLS.XlsFontUnderline.Single;
this.cellExport1.SheetOptions.NoteFormat.Alignment .Horizontal = Spire.DataExport.XLS.HorizontalAlignment.Left;
this.cellExport1.SheetOptions.NoteFormat.Alignment .Vertical = Spire.DataExport.XLS.VerticalAlignment.Top;
this.cellExport1.SheetOptions.NoteFormat.Font.Bold = true;
this.cellExport1.SheetOptions.NoteFormat.Font.Name = "Tahoma";
this.cellExport1.SheetOptions.NoteFormat.Font.Size = 8F;
this.cellExport1.SheetOptions.TitlesFormat.Font.Bo ld = true;
this.cellExport1.SheetOptions.TitlesFormat.Font.Na me = "Arial";
this.cellExport1.DataSource = DataExport.Common.ExportSource.ListView;
this.cellExport1.ListView = this.listView1;
Using (MemoryStream stream = new MemoryStream())
{
cellExport1.SaveToFile(stream);
this.oleDbConnection1.Close();
Workbook workbook = new Workbook(stream);
PdfConverter pdfConverter = new PdfConverter(workbook);
PdfDocument pdfDocument = new PdfDocument();
pdfDocument.PageSettings.Orientation = pdf.PdfPageOrientation.Landscape;
pdfDocument.PageSettings.Width = 970;
pdfDocument.PageSettings.Height = 850;
PdfConverterSettings settings = new PdfConverterSettings();
settings.TemplateDocument = pdfDocument;
pdfDocument = pdfConverter.Convert(settings);
pdfDocument.SaveToFile("test.pdf");
}
بایستی کتابخانه itextsharp.dll رو توی رفرنس پروژه اضافه کنی و همچنین در قسمت using هم این دو خط رو اضافه کنی
using iTextSharp.text;
using iTextSharp.text.pdf;
من کتابخانه مذکور رو با یه نمونه کامل از استفاده این کتابخانه براتون ضمیمه می کنمدر ضمن نحوه استفاده از این کتابخانه بصورت فایل pdf داخل نمونه به نمایش در می آید
نمونه روهمراه با کتابخانه از این لینک دریافت کنید http://uplod.ir/y4qpfgxbahlb/iiii.rar.htm