Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
3.8 kB
9
Indexable
Never
try
                    {
                        var workbook = new XLWorkbook(file.FileName);
                        var worksheet = workbook.Worksheet(1);
                        if (worksheet == null) return;
                        int i = 1;
                        string typecount = worksheet.Cell("D1").GetValue<string>();
                        if (string.IsNullOrEmpty(typecount)) typecount = worksheet.Cell("D2").GetValue<string>();
                        while (true)
                        {
                            i++;
                            string idpage = worksheet.Cell("A" + i).GetValue<string>();
                            PostInfo post = new PostInfo();

                            post.PageID = idpage;
                            post.IdPost = worksheet.Cell("B" + i).GetValue<string>();
                            post.TypePost = worksheet.Cell("C" + i).GetValue<string>();
                            if (string.IsNullOrEmpty(post.TypePost)) break;
                            if (!typecount.IsContains("View Count"))
                            {
                                try
                                {
                                    post.Like_Count = worksheet.Cell("D" + i).GetValue<int>();
                                    post.Share_Count = worksheet.Cell("E" + i).GetValue<int>();
                                    post.Comment_Count = worksheet.Cell("F" + i).GetValue<int>();
                                }
                                catch { }
                                post.Content = worksheet.Cell("G" + i).GetValue<string>();
                                post.ListUrlImage = new List<string>();
                                post.ListUrlImage = worksheet.Cell("H" + i).GetValue<string>().GetAllLine();
                                post.Url_video = worksheet.Cell("I" + i).GetValue<string>();
                                post.preset_id = worksheet.Cell("J" + i).GetValue<string>();
                                post.Linkshare = worksheet.Cell("K" + i).GetValue<string>();
                                post.Comment = worksheet.Cell("L" + i).GetValue<string>();
                                post.ID = DataGetPost_Thucong.Count + 1;
                                post.attachments = false;
                                if (post.ListUrlImage.Count > 0 || !string.IsNullOrEmpty(post.Url_video) || !string.IsNullOrEmpty(post.Linkshare)) post.attachments = true;
                            }
                            else
                            {
                                try
                                {
                                    post.Play_Count = worksheet.Cell("D" + i).GetValue<int>();
                                }
                                catch { }
                                numViewTT = numViewTT + post.Play_Count;
                                post.Content = worksheet.Cell("E" + i).GetValue<string>();
                            }
                            post.ID = DataGetPost_Thucong.Count + 1;
                            this.Dispatcher.Invoke(() =>
                            {
                                DataGetPost_Thucong.Add(post);
                            });

                        }
                        workbook.Dispose();
                        this.Dispatcher.Invoke(() =>
                        {
                            MessageBoxShow("Load thành công");
                        });

                    }
                    catch (Exception ex)
                    {
                        this.Dispatcher.Invoke(() =>
                        {
                            MessageBoxShow(ex.ToString());
                        });
                    }
Leave a Comment