Giter VIP home page Giter VIP logo

xlsf_with_c_sharp's Introduction

xlsf_with_C_sharp

A class of xls file with C#

想要仿照 xlsf_with_MFC的class使用方式 做一個C#版本的class

xls file with C sharp

xls file with C#

聲明

這是一份學C#沒多久,而寫出來的程式碼。

最大目的希望可以讓目前使用C#的人,可以更愉快一點!^^"

希望這個Class可以拋磚引玉,引起大家對於C#使用心得的話題,討論聊C#的使用心得。

作用

從C#加入Excel的參考,簡化它的function name

使用平台

  • OS: Windows 8.1
  • Tool: Visual Studio 2013
  • Reference: Excel 2013(其他版本沒有測試過)

檔案說明

  • main.cs Demo功能的主程式
  • xlsf.cs 定義檔

參考資料

Sample Code

用起來的code會像這樣

namespace XlsFile
{
    class Program
    {
        static void Main(string[] args)
        {
            xlsf excel_file = new xlsf();
            //xlsf excel_file = new xlsf(Marshal.GetActiveObject("Excel.Application"));

            //excel_file.NewFile();
            excel_file.OpenFile(@"C:\活頁簿1.xlsx");

            excel_file.SetVisible(true);

            excel_file.SelectCell("A1").SetCell("ID Number");
            excel_file.SelectCell("A1").AutoFitWidth();

            excel_file.SelectCell("B", 1).SetCell("Current Balance");
            excel_file.SelectCell("B", 1).AutoFitWidth();

            excel_file.SelectCell("A2").SetCellColor(Color.Beige);

            excel_file.SelectCell("A3", "B4").SetCellColor(Color.Black);
            excel_file.OffsetSelectCell(1, 2).SetCell("Black offset 1, 2");
            excel_file.AutoFitHight();

            excel_file.NewSheet();
            excel_file.SelectCell("B1").SetCell("this is B1");
            excel_file.SelectCell("B1").CopyCell("B1", "B5");

            excel_file.SelectCell("C1").SetCell("2016/3/16");
            excel_file.SelectCell("C1").SetFont("Console").SetFontSize(42).SetFontColor(Color.Blue).SetCellBk(Color.Orange);
            string datetime = excel_file.SelectCell("C1").GetCell2DateTime().ToString();
            Console.WriteLine(datetime);
            excel_file.SelectCell("D1").SetCell("this is D1");

            Console.WriteLine("SheetTotal:{0}", excel_file.SheetTotal());
            Console.WriteLine("SheetName:{0}", excel_file.GetSheetName());
            excel_file.SelectSheet(@"工作表1").SetSheetName("new sheet name");
            Console.WriteLine("SheetName:{0}", excel_file.GetSheetName());

            excel_file.SelectSheet(@"工作表3").CopySheet();
            excel_file.SelectCell("A1").SetCell(1);
            excel_file.SelectCell("A2").SetCell(2);
            excel_file.SelectCell("A3").SetCell(3);
            excel_file.SelectCell("A4").SetCell(4);
            excel_file.SelectCell("A4").SetCellHeight(36).SetCellWidth(68);
            excel_file.SelectCell("A5").SetCell("=SUM(A1:A4)");
            string str = excel_file.SelectCell("A5").GetCell2Str();
            Console.WriteLine(str);
            long number = excel_file.SelectCell("A5").GetCell2Int();
            Console.WriteLine(number);
            excel_file.SelectCell("A5").SetFontBold(true).SetFontStrkthrgh(true);
            excel_file.SelectSheet(2).CopySheet();
            //excel_file.DeleteSheet(2);

            Console.WriteLine("SheetTotal:{0}", excel_file.SheetTotal());
            excel_file.SelectSheet(@"工作表3").MoveSheet();
            //excel_file.SaveAs(@"C:\321.xlsx");
            //excel_file.CloseFile(false);
            //excel_file.Quit();
            Console.WriteLine("Press any key to exit.");
            Console.ReadKey();
        }
    }
}

xlsf_with_c_sharp's People

Contributors

dwatow avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.