Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Windows;
- using System.Drawing;
- using OfficeOpenXml;
- using OfficeOpenXml.Drawing;
- namespace PngToExcel
- {
- public partial class Form1 : Form
- {
- String pngfile = "mlp.bmp";
- String excelfile = "mylittleexcel.xlsx";
- Bitmap kucyk;
- int sizex = 0;
- int sizey = 0;
- public Form1()
- {
- InitializeComponent();
- button2.Enabled = false;
- String timeStamp = DateTime.Now.ToString("yyyyMMddHHmmssffff");
- excelfile = "mylittleexcel_" + timeStamp + ".xlsx";
- }
- private void DrawToExcel()
- {
- FileInfo newFile = new FileInfo(excelfile);
- using (ExcelPackage xlPackage = new ExcelPackage(newFile))
- {
- // do work here
- ExcelWorksheet worksheet = xlPackage.Workbook.Worksheets.Add("mylittlepony");
- for (int x = 0; x < sizex; x++)
- {
- for (int y = 0; y < sizey; y++)
- {
- worksheet.Cells[x + 1, y + 1].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
- worksheet.Cells[x+1,y+1].Style.Fill.BackgroundColor.SetColor(kucyk.GetPixel(y, x));
- worksheet.Column(x+1).Width = 3;
- //worksheet.Column(x+1).
- worksheet.Row(y+1).Height = 12;
- }
- }
- //worksheet.Cells["A1:B1"].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
- xlPackage.Save();
- }
- }
- private void ReadFromPng()
- {
- //Bitmap loadedBitmap = Bitmap.FromFile(openFileDialog1.Filename);
- kucyk = new Bitmap(pngfile);
- sizex = kucyk.Height;
- sizey = kucyk.Width;
- if(sizex != 0 && sizey != 0)
- {
- button2.Enabled = true;
- }
- }
- private void button1_Click(object sender, EventArgs e)
- {
- ReadFromPng();
- }
- private void button2_Click(object sender, EventArgs e)
- {
- DrawToExcel();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement