Advertisement
desdemona

giant pinkie pie

Oct 14th, 2014
407
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.50 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. using System.Windows;
  12. using System.Drawing;
  13. using OfficeOpenXml;
  14. using OfficeOpenXml.Drawing;
  15.  
  16. namespace PngToExcel
  17. {
  18.     public partial class Form1 : Form
  19.     {
  20.         String pngfile = "mlp.bmp";
  21.         String excelfile = "mylittleexcel.xlsx";
  22.         Bitmap kucyk;
  23.         int sizex = 0;
  24.         int sizey = 0;
  25.         public Form1()
  26.         {
  27.             InitializeComponent();
  28.             button2.Enabled = false;
  29.             String timeStamp = DateTime.Now.ToString("yyyyMMddHHmmssffff");
  30.             excelfile = "mylittleexcel_" + timeStamp + ".xlsx";
  31.         }
  32.  
  33.         private void DrawToExcel()
  34.         {
  35.             FileInfo newFile = new FileInfo(excelfile);
  36.             using (ExcelPackage xlPackage = new ExcelPackage(newFile))
  37.             {
  38.  
  39.                 // do work here
  40.                 ExcelWorksheet worksheet = xlPackage.Workbook.Worksheets.Add("mylittlepony");
  41.                 for (int x = 0; x < sizex; x++)
  42.                 {
  43.                     for (int y = 0; y < sizey; y++)
  44.                     {
  45.                         worksheet.Cells[x + 1, y + 1].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
  46.                         worksheet.Cells[x+1,y+1].Style.Fill.BackgroundColor.SetColor(kucyk.GetPixel(y, x));
  47.                         worksheet.Column(x+1).Width = 3;
  48.                         //worksheet.Column(x+1).
  49.                         worksheet.Row(y+1).Height = 12;
  50.                        
  51.                     }
  52.                 }
  53.                 //worksheet.Cells["A1:B1"].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
  54.                
  55.                 xlPackage.Save();
  56.  
  57.  
  58.             }
  59.         }
  60.  
  61.         private void ReadFromPng()
  62.         {
  63.             //Bitmap loadedBitmap = Bitmap.FromFile(openFileDialog1.Filename);
  64.             kucyk = new Bitmap(pngfile);
  65.             sizex = kucyk.Height;
  66.             sizey = kucyk.Width;
  67.             if(sizex != 0 && sizey != 0)
  68.             {
  69.                 button2.Enabled = true;
  70.             }
  71.         }
  72.  
  73.         private void button1_Click(object sender, EventArgs e)
  74.         {
  75.             ReadFromPng();
  76.         }
  77.  
  78.         private void button2_Click(object sender, EventArgs e)
  79.         {
  80.             DrawToExcel();
  81.         }
  82.     }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement