代码改变世界
[登录 · 注册]
  • NPOI导出Excel,添加图片和设置格式,添加条形码
  • 先上代码

      1 using grproLib;
      2 using System;
      3 using System.Collections.Generic;
      4 using System.Data;
      5 using System.Data.SqlClient;
      6 using System.IO;
      7 using System.Net;
      8 using System.Security.Cryptography;
      9 using System.Text;
     10 using System.Web.Script.Serialization;
     11 
     12 namespace shopeePrint
     13 {
     14     class Program
     15     {
     16         //static string ConnectionStr = "uid=gkweb_ticnL;pwd=gtIddQVVbSd89*@r%E;database=GBWMSDB;server=117.48.196.54,2859;Pooling=true;Min Pool Size=5;Max Pool Size=1000";
     17 
     18         static void Main(string[] args)
     19         {
     20             string url = "https://sellercenter-api.jumia.com.ng/?";
     21             //string Action = "FeedList";
     22             string Action = "GetDocument";
     23             string Format = "JSON";
     24             string Timestamp = System.Web.HttpUtility.UrlEncode(DateTime.Now.AddDays(-1).ToString("s") + "+0000", System.Text.Encoding.Default); ;
     25             //string Timestamp = DateTime.Now.AddDays(-1).ToString("s") + "+0000";
     26             string UserID = "jumia888999@gmail.com";
     27             string Version = "1.0";
     28             string Signature = "7c40abd44eeb21009edcb03f045360bdeec3a70d";
     29             string DocumentType = "invoice";//'invoice', 'exportInvoice', 'shippingLabel', 'shippingParcel', 'carrierManifest', or "serialNumber".
     30             string OrderItemIds = "[377847952]";
     31             string str = string.Format("Action={0}&Format={1}&Timestamp={2}&UserID={3}&Version={4}&Signature={5}&DocumentType={6}&OrderItemIds={7}"
     32                 , Action, Format, Timestamp, UserID, Version, Signature,DocumentType, OrderItemIds);
     33             //str = System.Web.HttpUtility.UrlEncode(str, System.Text.Encoding.Default);
     34             string urlstr = url + str;
     35             Console.WriteLine(urlstr);
     36             Program.WriteLog(urlstr);
     37             HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(urlstr);
     38             string result = "";
     39             try
     40             {
     41                 HttpWebResponse httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
     42                 using (StreamReader streamReader = new StreamReader(httpResponse.GetResponseStream()))
     43                 {
     44                     result = streamReader.ReadToEnd();
     45                     Console.WriteLine(result);
     46                     Program.WriteLog(result);
     47                 }
     48             }
     49             catch (Exception err)
     50             {
     51                 //msg = err.Message;
     52             }
     53             //string json = new JavaScriptSerializer().Serialize(param);
     54             //string result = GetMessageResult(json, shoopurl, key, out msg);
     55             //shopeeOrderList shooporders = new JavaScriptSerializer().Deserialize<shopeeOrderList>(result);
     56         }
     57         private static void WriteLog(string msg)
     58         {
     59          
     60             //当前程式目录创建Log目录
     61             string path = AppDomain.CurrentDomain.BaseDirectory;
     62             if (!Directory.Exists(path))
     63             {
     64                 Directory.CreateDirectory(path);
     65             }
     66             string fileName = DateTime.Now.ToString("yyyy-MM-dd");
     67 
     68             string filepath = path + fileName + ".txt";
     69 
     70             Stream fileStream = null;
     71             StreamWriter writeAdapter = null;
     72             fileStream = File.Open(filepath, FileMode.Append, FileAccess.Write, FileShare.Write);
     73             writeAdapter = new StreamWriter(fileStream, System.Text.Encoding.UTF8);
     74             writeAdapter.WriteLine("***********" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "************");
     75             writeAdapter.WriteLine("Message::::" + msg);
     76             writeAdapter.WriteLine("***********End*********************************************************");
     77             writeAdapter.WriteLine(" ");
     78             writeAdapter.Close();
     79         }
     80 
     81         private static string GetMessageResult(string json , string url, string key, out string msg)
     82         {
     83             msg = "";
     84             string input = string.Format("{0}|{1}", url.Replace(" ", ""), json.Replace(" ", ""));
     85             HMACSHA256 hm256 = new HMACSHA256(ASCIIEncoding.ASCII.GetBytes(key));
     86             byte[] hashBytes = hm256.ComputeHash(ASCIIEncoding.ASCII.GetBytes(input));
     87             string authe = BitConverter.ToString(hashBytes).Replace("-", "").ToLower();
     88 
     89             HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
     90             httpWebRequest.ContentType = "application/json";
     91             byte[] bytes = System.Text.Encoding.ASCII.GetBytes(json);
     92             httpWebRequest.ContentLength = bytes.Length;
     93             httpWebRequest.Method = "POST";
     94             httpWebRequest.Headers["Authorization"] = authe;
     95             httpWebRequest.KeepAlive = false;
     96 
     97             Stream requestStream = httpWebRequest.GetRequestStream();
     98             requestStream.Write(bytes, 0, bytes.Length);
     99             requestStream.Close();
    100             string result = "";
    101             try
    102             {
    103                 HttpWebResponse httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
    104                 using (StreamReader streamReader = new StreamReader(httpResponse.GetResponseStream()))
    105                 {
    106                     result = streamReader.ReadToEnd();
    107                     Program.WriteLog(result);
    108                     Console.WriteLine(result);
    109                 }
    110             }
    111             catch (Exception err)
    112             {
    113                 msg = err.Message;
    114             }
    115             return result;
    116         }
    117 
    118     }
    119 
    120     class FeedListParam
    121     {
    122         public string Action { get; set; }
    123         public string Format { get; set; }
    124         public string Timestamp { get; set; }
    125         public string UserID { get; set; }
    126         public string Version { get; set; }
    127         public string Signature { get; set; }
    128         public string CreatedAfter { get; set; }
    129         public string CreatedBefore { get; set; }
    130         public string Search { get; set; }
    131         public string Filter { get; set; }
    132         public string Limit { get; set; }
    133         public string Offset { get; set; }
    134         public string SkuSellerList { get; set; }
    135         public string UpdatedAfter { get; set; }
    136         public string UpdatedBefore { get; set; }
    137         public string GlobalIdentifier { get; set; }
    138     }
    139 
    140 }
    View Code

    项目引用NPOI

    测试输出的Excel  显示条形码

    设置边框

     

  • 原文地址:https://www.cnblogs.com/sunbingqiang/p/7911913.html
Copyright 2008-2020 晋ICP备12007731号-1